Skip to main content

Call a web trigger from Jira Automation

Run a Script Master script whenever something happens in Jira, by letting a Jira Automation flow call a web trigger. This example adds the label triaged to every new work item in a space.

Applies to: Script Master for Jira Β· Cloud

Script Master has no event listeners. Jira Automation already reacts to events such as Work item created, with JQL conditions and an audit log. Its Send web request action sends the work item's data to your web trigger, and the script does what Automation can't.

Before you begin​

  • Jira permission: Jira admin (the Administer Jira global permission) for Script Master, and permission to create automation flows in the space.
  • App permission: an active Script Master license.
  • A configured Companion App. See Set up the Companion App.
  • A long random token. The flow sends it, and the script checks it.

Create the web trigger​

  1. In Script Master, select the Web Triggers tab, then Create web trigger.

  2. In Title, enter Label new work items.

  3. In Backend JavaScript, paste the script below. Replace <your-access-token> with your token.

    if (request.headers['authorization']?.[0] !== 'Bearer <your-access-token>') {
    return { statusCode: 401, statusText: 'Unauthorized' };
    }
    if (!request.body) {
    return { statusCode: 400, statusText: 'No work item data' };
    }

    // The flow sends the work item as JSON: key, fields and more
    const workItem = JSON.parse(request.body);

    const response = await api.asApp().requestJira(route`/rest/api/3/issue/${workItem.key}`, {
    method: 'PUT',
    headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
    body: JSON.stringify({ update: { labels: [{ add: 'triaged' }] } }),
    });

    if (!response.ok) {
    console.error(`Jira answered ${response.status} for ${workItem.key}`, await response.text());
    return { statusCode: 502, statusText: 'Jira update failed' };
    }
    return { statusCode: 200, statusText: 'OK' };
  4. Turn on Enable, then select Save.

  5. Select the copy icon next to Web Trigger URL: to copy the URL.

    A web trigger titled Label new work items, with its URL and the Enable switch on

Create the automation flow​

Jira Automation calls its rules flows.

  1. In Jira, open the space's automation and select Create flow, then Create from scratch. See Jira automation triggers.

  2. Choose the trigger Work item created.

  3. Add the action Send web request.

  4. In Web request URL, paste the web trigger URL.

  5. Set HTTP method to POST, and Web request body to Issue data (Automation format).

  6. Under Headers (optional), enter the Key Authorization and the Value Bearer <your-access-token>. Select Hidden, so the flow shows dots instead of your token.

    A Send web request action with the web trigger URL, POST, Issue data (Automation format) and a hidden Authorization header

  7. Select Save and enable.

PlaceholderDescription
<your-access-token>Your secret token. Use the same value in the script and in the flow's header.

Result: Create a work item in the space. Shortly after, it has the label triaged.

Check what happened​

  • In Script Master, the web trigger's History column shows the call. Select its dot to read the response, the output lines and any error. See Run history.
  • In Jira Automation, the flow's audit log shows whether the web request succeeded.
  • Before you turn the flow on, you can try the script with Test a web trigger. Put a work item's data, as a JSON string, in the request's body.
note

A web trigger runs as the app. Jira shows your Companion App as the one that added the label, not the user who created the work item.

When many work items change at once​

Script Master accepts about 10 web trigger calls in 20 seconds, shared by all web triggers on the site. A burst, such as a bulk create or a CSV import, fires the flow for every work item, and calls over the limit get 429 Too Many Requests. The script doesn't run for those work items.

To catch them:

  • Check the flow's audit log in Jira Automation. Failed web requests are listed there.
  • Run the work again for the work items that failed, for example with a manual flow on a JQL search for work items without the label.

See Limits.

Use the same approach for other events​

Pick another trigger, for example one for transitions or comments, and change what the script does. Return 200 when the work is done, and an error status, such as 502, when it isn't.

Confluence Automation can call a web trigger in Script Master for Confluence the same way.