Authenticating With the API

To authenticate against the Snipe-IT API, you'll need to pass an Authorization, Accept: application/json and Content-Type: application/json header with every request.

It should look something like this, if your API key were MY-AWESOME-API-KEY:

HeaderValue
AuthorizationBearer MY-AWESOME-API-KEY
Acceptapplication/json
Content-Typeapplication/json

In reality, your API Key will be much longer than that, but you get the idea.

For example, using the Guzzle library:

$accessToken = 'MY-AWESOME-API-KEY';

$response = $client->request('GET', '/api/users', [
    'headers' => [
        'Accept' => 'application/json',
        'Content-Type' => 'application/json',
        'Authorization' => 'Bearer '.$accessToken,
    ],
]);

🚧

Be sure to include BOTH the Content-Type AND Accept headers with your request!

If your API request returns a login page (or any HTML page) and you're certain you're passing the Bearer token correctly in the Authorization header, double-check that you are passing both the Content-Type and Accept headers, and that the value of those headers is application/json.