> For the complete documentation index, see [llms.txt](https://docs.pagerly.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pagerly.io/task-management/assign-tickets-to-current-oncall/assign-jira-tickets-to-current-oncall.md).

# Assign Jira Tickets to the Current Oncall

Fill the Jira assignee field with whoever is on call — via Jira Automation, the Jira REST API, or Pagerly's Slack integration.

Three ways to do this, in increasing order of control.

1. **Jira Automation** — no code, runs inside Jira, covers every issue created in a project.
2. **Jira REST API** — for tickets created by your own services.
3. **Pagerly's Slack integration** — for tickets raised from a Slack thread or emoji reaction.

## Prerequisites

* A Pagerly team with a schedule. See [Create Round Robin Rotations](/oncall-and-rotations/create-round-robin-rotations.md).
* A [Pagerly API key](/api-and-developers/generate-api-key.md) for options 1 and 2.
* [Your Jira account connected to Pagerly](/integrations/integration-with-jira/add-your-jira-account.md) for option 3.
* Your on-call users' Pagerly emails must match their Atlassian account emails.

## Option 1 — Jira Automation (recommended)

The rule is two components: fetch the on-call `accountId` from Pagerly, then assign the issue to it.

### Build the rule

1. Create a new automation rule with the trigger you want — **Work item created** is the usual one. Narrow it with a condition if you only want it on bugs (`Work item type equals Bug`).
2. Click **Add component → Action → Send web request**.
3. Set **Web request URL** to:

   ```
   https://api.pagerly.io/pagerly/o/currentusersforjira?teamname=<teamname>
   ```

   Replace `<teamname>` with your Pagerly team's name.
4. Set **HTTP method** to `GET`. Leave the body empty.
5. Add a header:

   | Header     | Value                |
   | ---------- | -------------------- |
   | `X-APIKEY` | Your Pagerly API key |
6. **Tick "Delay execution of subsequent rule actions until we've received a response for this web request".**

{% hint style="danger" %}
Step 6 is the one people miss. Without it the rule races ahead to the assign action before the response arrives, the smart value is empty, and the issue is left unassigned with no error in the audit log.
{% endhint %}

7. Click **Add component → Action → Assign work item**.
8. Choose **Smart value** as the assignment method.
9. Under **User**, enter:

   ```
   {{webhookResponse.body.accountId}}
   ```
10. Save and enable the rule.

### What the endpoint returns

```bash
curl --location 'https://api.pagerly.io/pagerly/o/currentusersforjira?teamname=devops' \
  --header 'X-APIKEY: <API-KEY>'
```

```json
{ "accountId": "63c18e6494d18cbf677351fa" }
```

Pagerly resolves the current on-call user for the team, looks their email up in your connected Jira instance, and returns the Atlassian `accountId` — so the automation never has to do its own user search.

### Handling nobody-on-call

If the schedule has a gap, there is no on-call user to resolve. Add a **Condition** between the two components:

```
{{webhookResponse.body.accountId}} is not empty
```

and, on the else branch, assign to a fallback lead or add a comment tagging the team so the ticket does not disappear.

### Reassigning at shift handover

The rule above assigns at creation. If you also want open tickets to follow the rota, add a second **Scheduled** rule that runs at your handover time with a JQL filter such as:

```
project = SUP AND status = "In Progress" AND labels = follows-oncall
```

and the same two components. Label the tickets you want to travel; leave the rest with their owner.

## Option 2 — Jira REST API

For tickets your own code creates. Two calls: ask Pagerly who is on call, then `PUT` the assignee.

```bash
# 1. Who is on call?
ACCOUNT_ID=$(curl -s \
  'https://api.pagerly.io/pagerly/o/currentusersforjira?teamname=devops' \
  -H "X-APIKEY: $PAGERLY_API_KEY" | jq -r '.accountId')

# 2. Assign the issue
curl -s -X PUT \
  "https://your-domain.atlassian.net/rest/api/2/issue/SUP-1423" \
  -u "$JIRA_EMAIL:$JIRA_API_TOKEN" \
  -H 'Content-Type: application/json' \
  -d "{\"fields\": {\"assignee\": {\"id\": \"$ACCOUNT_ID\"}}}"
```

A successful assignment returns `204 No Content`.

If you would rather resolve the account yourself — for example because you want the on-call user's name and Slack ID for a comment too — use the generic endpoint and Jira's user search:

```bash
curl -s 'https://api.pagerly.io/pagerly/o/currentusers?teamname=devops' \
  -H "X-APIKEY: $PAGERLY_API_KEY"
# [{"name":"mansi","email":"mansi@pagerly.io","id":"U04CTTV5Z6G","imageurl":null}]

curl -s -G "https://your-domain.atlassian.net/rest/api/3/user/search" \
  --data-urlencode "query=mansi@pagerly.io" \
  -u "$JIRA_EMAIL:$JIRA_API_TOKEN"
```

{% hint style="warning" %}
Jira only returns an email in user search if the user's profile visibility allows it. On many Atlassian instances email is withheld, and `query=` matching falls back to display name. If you hit this, use `/o/currentusersforjira` — Pagerly does the resolution on its side.
{% endhint %}

## Option 3 — from Slack, via Pagerly

If the ticket is being raised out of a Slack conversation, Pagerly creates it already assigned.

* [Create a ticket via emoji](/integrations/integration-with-jira/create-a-ticket-via-emoji-and-follow-on-slack-channel.md) — react to a message, Pagerly opens the Jira issue and assigns the team's current on-call.
* [Create a Jira ticket using a form](/integrations/integration-with-jira/create-jira-ticket-incident-using-form.md) — the assignee defaults to the on-call for the team the form is bound to.
* [Round Robin Assignment of Jira Issues/Tickets](/integrations/integration-with-jira/round-robin-assignment-of-jira-issues-tickets.md) — distribute across the rota per ticket instead of per shift.

The Slack thread and the Jira issue stay linked, so comments and status transitions flow both ways without anyone opening Jira.

## Troubleshooting

| Symptom                                 | Cause                                                            | Fix                                          |
| --------------------------------------- | ---------------------------------------------------------------- | -------------------------------------------- |
| Issue created, assignee empty, no error | "Delay execution…" not ticked on the web request                 | Tick it and re-run                           |
| `400` from the assign action            | `accountId` was empty — nobody on call                           | Add the not-empty condition and a fallback   |
| Rule assigns the wrong person           | `teamname` points at a different Pagerly team                    | Check the name with `GET /o/zapier/allteams` |
| `accountId` returned but assign fails   | User has no Jira licence, or no browse permission on the project | Grant access, or exclude them from the rota  |
| Worked yesterday, fails today           | Pagerly team was renamed                                         | Update the URL; alert on non-200 responses   |

## Related

* [Fetch Current Oncall / Rotated User via API](/api-and-developers/fetch-current-oncall-rotated-user-via-api.md)
* [Integration with Jira](/integrations/integration-with-jira.md)
* [Assign Linear Issues to the Current Oncall](/task-management/assign-tickets-to-current-oncall/assign-linear-issues-to-current-oncall.md)
