michaeldrennen/bugsnag-api-client

A PHP client library to interface with the BugSnag API.

Maintainers

Package info

github.com/michaeldrennen/BugSnagApiClient

pkg:composer/michaeldrennen/bugsnag-api-client

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0 2026-04-23 22:59 UTC

This package is auto-updated.

Last update: 2026-04-24 01:35:08 UTC


README

A robust PHP client library designed to easily interface with the Bugsnag Data Access API (v2).

Installation

Install the package via Composer:

composer require michaeldrennen/bugsnag-api-client

Authentication

To use this client, you must generate a Personal Auth Token from your Bugsnag dashboard.

  1. Log in to Bugsnag.
  2. Go to Settings > My Account > Personal auth tokens.
  3. Generate a new token.

Note: This token is different from your project-level "API Key" used for reporting errors.

Finding IDs and Credentials

Many API endpoints require specific IDs (like an Organization ID or Project ID). While you can extract these programmatically using the API itself (e.g., calling $client->getOrganizations()), you can also find them manually in your Bugsnag dashboard:

  • Organization ID: In the Bugsnag dashboard, navigate to Settings > Organization settings. The Organization ID is typically the 24-character hexadecimal string found in the URL. (e.g., https://app.bugsnag.com/settings/organizations/50baed0d9bf39c1431000003/...)
  • Project ID: Navigate to Settings > Project settings. Similar to the organization, the Data Access API requires the 24-character hexadecimal Project ID, which can be found in the URL while viewing the project settings.
  • Error ID & Event ID: When viewing a specific error or event in your Bugsnag dashboard, the long alphanumeric strings present in the URL are the respective IDs.

Basic Usage

Instantiate the client by passing your Personal Auth Token.

use MichaelDrennen\BugSnagApiClient\BugsnagApiClient;

require 'vendor/autoload.php';

// Initialize the client
$token = 'your-personal-auth-token';
$client = new BugsnagApiClient($token);

Retrieving Organizations

Get a list of all organizations your user account belongs to:

$organizations = $client->getOrganizations();

foreach ($organizations as $org) {
    echo "Organization ID: " . $org['id'] . " - Name: " . $org['name'] . "\n";
}

Get details for a specific organization by its ID:

$orgId = '50baed0d9bf39c1431000003';
$organization = $client->getOrganization($orgId);

Retrieving Projects

Fetch all projects under a specific organization:

$projects = $client->getProjects($orgId);

foreach ($projects as $project) {
    echo "Project ID: " . $project['id'] . " - Name: " . $project['name'] . "\n";
}

Retrieving Errors and Events

Fetch a list of errors for a given project. You can optionally pass an array of query parameters to filter the results according to the Bugsnag API documentation.

$projectId = 'project-id-string';

// Fetch open errors
$filters = [
    'base_error.status' => 'open'
];

$errors = $client->getErrors($projectId, $filters);

Get details for a specific error:

$errorId = 'error-id-string';
$error = $client->getError($projectId, $errorId);

Fetch events (individual occurrences of an error):

$events = $client->getEvents($projectId);

Get details for a specific event:

$eventId = 'event-id-string';
$event = $client->getEvent($projectId, $eventId);

Making Custom Requests

If you need to hit an endpoint that isn't explicitly mapped in the client, you can use the generic get() method.

// Fetch users for an organization
$users = $client->get("organizations/{$orgId}/users");

Testing

This package uses PHPUnit for testing. The test suite includes both mocked unit tests and live integration tests.

Running Unit Tests

Unit tests mock the Guzzle HTTP client, so no real API requests are made.

composer run-script test
# or
./vendor/bin/phpunit

Running Integration Tests

To run the integration tests against the live Bugsnag API:

  1. Copy phpunit.xml.dist to phpunit.xml.
  2. Open phpunit.xml and replace your-real-token-here with your actual Bugsnag Personal Auth Token.
  3. Run PHPUnit:
./vendor/bin/phpunit

Warning: Do not commit phpunit.xml to version control if it contains your real API token. The .gitignore file is already configured to ignore it.

License

The MIT License (MIT). Please see License File for more information.