How to Start Root Cause Analysis and Resolve Runs From the Rollbar API

How to Start Root Cause Analysis and Resolve Runs From the Rollbar API
Table of Contents

A CI job that rolls back a bad release can also start root cause analysis on the Rollbar item behind the rollback, have Resolve open a pull request with a fix, and print that pull request’s link in its own log. The job calls the Agent Tasks endpoints in the Rollbar API to start the analysis, checks its status until it finishes, starts Resolve with a second call, and checks again until the pull request URL comes back. A deploy pipeline, a runbook script, or an AI coding agent can make the same calls without anyone opening the Rollbar UI.

Why start root cause analysis and Resolve from your own tools

  • Any job that can name the Rollbar item behind a failure can start the analysis as its next step, whether that job is a rollback, a failed post-deploy check, or a runbook someone runs during an incident. Nobody has to see the alert, find the item in Rollbar, and start a run by hand in the middle of the night.
  • When the Resolve run finishes, the status call returns its pull request URL, so the job that started it can post the link to your incident channel or attach it to the ticket your runbook opens.
  • Your script can send Resolve the same fix requirements on every run, such as keeping the change inside one service and adding a regression test. When the pull request needs changes, the script or your AI coding agent sends feedback through the API, and Resolve applies it to the pull request it already opened.

TL;DR

  • A deploy pipeline, a runbook script, or an AI coding agent can start Rollbar root cause analysis on a production error and get back a link to a Resolve pull request, without anyone opening the Rollbar UI.
  • One POST to /api/1/agent_tasks/rca starts root cause analysis on an item, identified by its project slug and item number or by an occurrence ID, and setting continue_with_resolve to true starts Resolve after the analysis completes.
  • GET /api/1/agent_tasks/{task_session_id} returns a run’s status and, once the run finishes, its results, including pull_request_url for a Resolve run.
  • POST /api/1/agent_tasks/{task_session_id}/feedback sends feedback that Resolve applies to the pull request it already opened.
  • Every call needs a personal access token (write scope to start runs and send feedback, read scope to check them), and the account must have AI features enabled.

Before you start

  1. AI features enabled on your Rollbar account. An account owner turns them on under Account Settings → Agents, and until then every call returns 403.
  2. A personal access token with write scope to start runs and send feedback, and read scope to check status and list runs. Rollbar refuses project access tokens and service tokens on these endpoints, and Step 1 creates the token.
  3. The Rollbar GitHub App installed, with your repository mapped to the project. If you already run root cause analysis from the Rollbar UI, this is in place.
  4. A user on a team with Standard or Owner access to the item’s project, so the personal access token you create carries the roles these calls need.
  5. curl and jq. The examples use jq to read fields out of the JSON responses.

Step 1: Create a personal access token with read and write scope

Open User Settings in Rollbar, go to Personal access tokens, and create a token with both scopes.

The token stops working when you are removed from the account, so a CI job that depends on it needs a teammate’s token before you leave. Our guide to posting a script’s result as a comment on a Rollbar item covers creating and storing the token in more detail.

Keep the token in an environment variable, or in your CI system’s secrets store under the same name:

export ROLLBAR_TOKEN="paste-your-token-here"

Step 2: Start root cause analysis by project slug and item number

project_slug is the project slug from the item’s URL in Rollbar, and item_counter is the item number shown within the project. With those two values, Rollbar analyzes the item’s latest occurrence.

TASK_ID=$(curl --silent -X POST "https://api.rollbar.com/api/1/agent_tasks/rca" \
  --header "X-Rollbar-Access-Token: $ROLLBAR_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"project_slug": "my-project", "item_counter": 123}' \
  | jq -r '.result.task_session_id')
echo "$TASK_ID"

A successful response has this shape:

{"err": 0, "result": {"task_session_id": "TASK_SESSION_ID", "source_occurrence_id": "OCCURRENCE_ID"}}

Every later call uses task_session_id to find the run, and source_occurrence_id is the occurrence Rollbar picked. To analyze a specific occurrence, send {"source_occurrence_id": "OCCURRENCE_ID"} on its own. A request that sends both forms, or neither, returns 400.

Step 3: Chain Resolve so the run ends in a pull request

Add "continue_with_resolve": true and Rollbar starts Resolve automatically after the analysis completes. The default is false, which stops at the analysis.

TASK_ID=$(curl --silent -X POST "https://api.rollbar.com/api/1/agent_tasks/rca" \
  --header "X-Rollbar-Access-Token: $ROLLBAR_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"project_slug": "my-project", "item_counter": 123, "continue_with_resolve": true}' \
  | jq -r '.result.task_session_id')

The response carries the analysis run’s task_session_id. Poll it with the function in Step 4 to know when the analysis has finished, and follow the Resolve run it starts on the item’s Root cause & fix tab in Rollbar.

When a script needs the pull request URL, or you want to give Resolve requirements for the fix, start Resolve yourself. Send the Step 2 request without continue_with_resolve, and once the analysis has finished, call POST /api/1/agent_tasks/resolve with the analysis run’s ID as rca_task_session_id. The call accepts optional initial_instructions of up to 4,000 characters and returns the Resolve run’s own task_session_id. This function wraps it, and Step 4 shows where it goes in a pipeline:

start_resolve() {
  curl --silent -X POST "https://api.rollbar.com/api/1/agent_tasks/resolve" \
    --header "X-Rollbar-Access-Token: $ROLLBAR_TOKEN" \
    --header "Content-Type: application/json" \
    --data "$(jq -n --arg rca "$1" --arg instructions "${2:-}" \
      '{rca_task_session_id: $rca} + (if $instructions == "" then {} else {initial_instructions: $instructions} end)')" \
    | jq -r '.result.task_session_id'
}

In the Rollbar UI, the same kind of instructions go on the item’s Root cause & fix tab, which our post on telling Resolve which fix to take covers. If you want every matching production error analyzed without a script, an Agent Automation rule starts runs from inside Rollbar.

Step 4: Poll the run and read its results

GET /api/1/agent_tasks/{task_session_id} returns the run’s agent_type (rca or resolve) and its status, which is one of queued, running, blocked, canceling, finished, failed, or canceled. Results appear only after the run finishes.

This function checks every 30 seconds and prints the run once it is finished, failed, canceled, or blocked:

wait_for_run() {
  while true; do
    RUN=$(curl --silent \
      --header "X-Rollbar-Access-Token: $ROLLBAR_TOKEN" \
      "https://api.rollbar.com/api/1/agent_tasks/$1")
    if [ "$(echo "$RUN" | jq -r '.err')" != "0" ]; then
      echo "$RUN" >&2
      return 1
    fi
    STATUS=$(echo "$RUN" | jq -r '.result.status')
    echo "Run $1 is $STATUS" >&2
    case "$STATUS" in
      finished|failed|canceled|blocked) echo "$RUN"; return 0 ;;
    esac
    sleep 30
  done
}

In a pipeline step, wait for the analysis started in Step 2, start Resolve with start_resolve once the analysis has finished, and wait for the Resolve run:

RCA_RUN=$(wait_for_run "$TASK_ID")
if [ "$(echo "$RCA_RUN" | jq -r '.result.status')" = "finished" ]; then
  RESOLVE_ID=$(start_resolve "$TASK_ID" "Keep the change inside the checkout service and add a regression test for an empty cart.")
  RESOLVE_RUN=$(wait_for_run "$RESOLVE_ID")
  echo "$RESOLVE_RUN" | jq -r '.result.resolve_results.pull_request_url'
fi

What to read depends on the run:

  • A finished analysis carries rca_results, which includes the root cause when one was found: echo "$RCA_RUN" | jq '.result.rca_results'.
  • A finished Resolve run carries resolve_results, and its pull_request_url is the pull request Resolve opened, which the last line of the pipeline block prints.
  • A failed run includes failure_reason, with an agent_failure_code and a message, when Rollbar recorded one.
  • For a blocked run, open the item’s Root cause & fix tab in Rollbar, where a blocked task says why it stopped.

Step 5: Find the runs on an item

GET /api/1/agent_tasks lists the runs on an item that have not expired, newest first. Each entry has a task_session_id, an agent_type, a status, and a date_created in Unix seconds.

curl --silent \
  --header "X-Rollbar-Access-Token: $ROLLBAR_TOKEN" \
  "https://api.rollbar.com/api/1/agent_tasks?project_slug=my-project&item_counter=123" \
  | jq '.result.tasks'

Check the list before you start a run, because a start request returns 409 while another agent task is active, and you can poll the active run instead. The list returns up to 50 runs per page by default (limit goes to 100). Pass next_offset as offset until it comes back null, and expect some pages to hold fewer runs than limit, because Rollbar removes runs your user cannot view.

Step 6: Send feedback on the Resolve pull request

When the pull request needs changes, send feedback in the content field, which cannot be blank, to the completed Resolve run. Resolve applies it to the pull request it already opened, and the response carries a task_session_id to poll and a feedback_id.

FEEDBACK_RUN=$(curl --silent -X POST "https://api.rollbar.com/api/1/agent_tasks/$RESOLVE_ID/feedback" \
  --header "X-Rollbar-Access-Token: $ROLLBAR_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"content": "Also handle a null cart ID, and add a test for it."}' \
  | jq -r '.result.task_session_id')

wait_for_run "$FEEDBACK_RUN" | jq -r '.result.resolve_results.pull_request_url'

When a call returns an error

  • 400: The start request sent both source_occurrence_id and project_slug with item_counter, or neither, or an invalid continue_with_resolve value. On the feedback call, content was missing or blank.
  • 403: The token is not a personal access token with the scope the call needs, your user lacks permission on the project or a correlated project, or AI features are off for the account. A project none of your teams can access returns the message Requires project access.
  • 404: No project or item with that slug and number exists in your account. On the status, Resolve, and feedback calls, it means the run does not exist in your account or has expired.
  • 409: An agent task is already active, so list the item’s runs and poll that one. On the feedback call, it means that feedback has already requested a continuation.
  • 422: The item has no occurrence, validation failed, or Rollbar could not create the task. On the feedback call, the Resolve run cannot accept feedback, or its pull request or credits are unavailable.
  • 503: Feedback calls only. Rollbar recorded the feedback but could not deliver it, and sending the same feedback again is safe.

Read the Agent Tasks API reference

FAQ

Can I start Rollbar root cause analysis through the API?
Yes. Send a POST request to /api/1/agent_tasks/rca with the project slug and item number, or an occurrence ID, using a personal access token with write scope. The account must have AI features enabled.

Which tokens do the Rollbar Agent Tasks endpoints accept?
Only personal access tokens. Starting a run or sending feedback needs write scope, and checking status or listing runs needs read scope. Rollbar refuses project access tokens and service tokens, and you create a personal access token in User Settings → Personal access tokens.

Can one API call end in a fix pull request?
Yes. Set continue_with_resolve to true when you start root cause analysis, and Rollbar starts Resolve automatically after the analysis completes. Resolve opens the pull request and leaves the merge to your team.

How do I get the pull request URL from a Resolve run?
Call GET /api/1/agent_tasks/{task_session_id} with the Resolve run’s task session ID. When its status is finished, resolve_results.pull_request_url holds the pull request.

Can an AI coding agent start these runs?
Yes, through the Rollbar MCP server. Its start-rca, start-resolve, get-agent-task-status, list-agent-tasks, and send-resolve-feedback tools call the same endpoints with a personal access token.

Build with confidence. Release with clarity.

Rollbar helps you track what breaks, understand why, and improve what comes next.

✓ 5K free events per month, forever
✓ 14-day full feature trial
✓ Easy and quick installation
Get started in minutes

Plans starting at $0. Take off with our 14-day full feature Free Trial.