Example API requests

Example use cases for the data access API.

Examples

Each example includes a curl request and a portion of a possible response. See the API reference for full details of the parameters and responses.

Note: Examples with URL parameters are shown over multiple lines for clarity but the whitespace must be removed before execution.

Getting started

For most API endpoints you’ll require a organization ID or a project ID. You can get these from the List Organizations and List Projects endpoints.

$ curl --get 'https://api.bugsnag.com/user/organizations' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
    {
        "id": "5919dd35488ed9001b53f3c3",
        "name": "Example Org",
        "slug": "example-org",
        "created_at": "2017-05-15T16:54:13.525Z"
        ... // More fields
    }
]
$ curl --get 'https://api.bugsnag.com/organizations/{organization_id}/projects' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
    {
        "id": "50baee27a43ccdf778000002",
        "created_at": "2016-12-02T05:59:03.903Z",
        "api_key": "abcde1234567890abcde123456",
        "name": "Example Project",
        "type": "rails",
        "collaborators_count": 23,
        "open_error_count": 5,
        "release_stages": [
            "production"
        ],
        "slug": "example-project",
        ... // More fields
    }
    ...
]

Errors seen in a specific version

To find all the errors that have been seen in a specific version on a project, use the List Errors endpoint.

$ curl --get --globoff 'https://api.bugsnag.com/projects/{project_id}/errors?
                filters[version.seen_in][][value]={your_app_version}&
                filters[version.seen_in][][type]=eq' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
  {
    "id": "5952b72acce9f50018a14515",
    "status": "open",
    "severity": "error",
    "error_class": "ExampleError",
    "message": "Can't find variable: example",
    "context": "api/users",
    "first_seen": "2017-06-27T19:51:06+00:00",
    "last_seen": "2017-06-27T19:51:06+00:00",
    "release_stages": [
      "production"
    ]
    ... // More fields
  },
  ...
]

Users that experienced a specific error

To get the details of all the users who have experienced a specific error, use the Pivot Values endpoint. user.id is the event_field_display_id for user information.

$ curl --get --globoff 'https://api.bugsnag.com/projects/{project_id}/errors/{error_id}/pivots/user.id/values? \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
    {
        "event_field_value": "10000005",
        "events": 14,
        "fields": {
            "user.email": "user1@example.com",
            "user.name": "User One"
        },
        "first_seen": "2017-06-28T20:27:45+00:00",
        "last_seen": "2017-06-28T20:34:44+00:00",
        "proportion": 0.43324
    },
    {
        "event_field_value": "10000025",
        "events": 5,
        "fields": {
            "user.email": "user2@example.com",
            "user.name": "User Two"
        },
        "first_seen": "2017-06-27T20:16:43+00:00",
        "last_seen": "2017-07-03T15:40:18+00:00",
        "proportion": 0.15007
    },
    ...
]

Users that have seen an error the most in the last week

To find the users who have experienced an error the most in the last week, use the Pivot Values endpoint. user.id is the event_field_display_id for user information and the 7d filter will restrict the data to the last 7 days.

$ curl --get --globoff 'https://api.bugsnag.com/projects/{project_id}/errors/{error_id}/pivots/user.id/values?
                filters[event.since][][value]=7d&
                filters[event.since][][type]=eq' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
    {
        "event_field_value": "10000005",
        "events": 14,
        "fields": {
            "user.email": "user1@example.com",
            "user.name": "User One"
        },
        "first_seen": "2017-06-28T20:27:45+00:00",
        "last_seen": "2017-06-28T20:34:44+00:00",
        "proportion": 0.43324
    },
    {
        "event_field_value": "10000025",
        "events": 5,
        "fields": {
            "user.email": "user2@example.com",
            "user.name": "User Two"
        },
        "first_seen": "2017-06-27T20:16:43+00:00",
        "last_seen": "2017-07-03T15:40:18+00:00",
        "proportion": 0.15007
    },
    ...
]

Build a graph of events over time

Get the data to build a graph showing event counts in 30 minute buckets over a day using the Trends endpoint.

$ curl --get --globoff 'https://api.bugsnag.com/projects/{project_id}/trend?
                resolution=30m&
                filters[event.since][][value]=1d&
                filters[event.since][][type]=eq' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
   {
       "events_count": 48,
       "from": "2017-07-10T00:00:00Z",
       "to": "2017-07-10T00:30:00Z"
   },
   {
       "events_count": 96,
       "from": "2017-07-10T00:30:00Z",
       "to": "2017-07-10T01:00:00Z"
   },
   ...
]

Get the active errors that are assigned to your team

Get all the active errors that haven’t been fixed but are assigned to a collaborator on your team using the List Errors endpoint.

$ curl --get --globoff 'https://api.bugsnag.com/projects/{project_id}/errors?
                filters[error.assigned_to][][value]=anyone&
                filters[error.assigned_to][][type]=eq&
                filters[error.status][][value]=open&
                filters[error.status][][type]=eq' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
  {
    "id": "5952b72acce9f50018a14515",
    "assigned_collaborator_id": "5952b72acce9f50018000000",
    "status": "open",
    "severity": "error",
    "error_class": "ExampleError",
    "message": "Can't find variable: example",
    "context": "api/users"
    ... // More fields
  },
  ...
]

Then get the collaborator details using the List Collaborators endpoint.

$ curl --get 'https://api.bugsnag.com/organizations/{organization_id}/collaborators' \
       --header 'Authorization: token {your_user_auth_token}' \
       --header 'X-Version: 2'
[
  {
      "id": "5952b72acce9f50018000000",
      "email": "collaborator@example.com",
      "is_admin": true,
      "name": "Collaborator One"
      ... // More fields
  }
  ...
]

Batch event retrieval and deletion

To request or delete a filtered list of events from BugSnag, use the Event data request and Event data deletion endpoints.

These endpoints are particularly important for GDPR & CCPA compliance in order to retrieve and delete user data.

Your examples

If you have an example use case you’d like to share or an idea you’d like some help with, please get in touch with us.