Skip to main content

Authentication Guide

Learn how to authenticate with the Stockaj API and manage access tokens.

Token Types

Stockaj uses Laravel Sanctum tokens. There are two token contexts:

TypeCreated ByUse Case
User TokenUser via profile/APIFull API access scoped to user's permissions
Instance TokenWorkspace admin via SettingsWorkspace-level API access with fine-grained abilities

For most integrations, Instance Tokens are recommended — they're tied to a workspace and have explicit ability control.

Creating Tokens

Via the Web UI

  1. Go to Settings → API Tokens.
  2. Click + New Token.
  3. Name your token (e.g., warehouse-scanner-prod).
  4. Select abilities.
  5. Click Create and immediately copy the token.
warning

The token is shown only once at creation time. If you lose it, you'll need to create a new one.

Token Naming Conventions

Use descriptive names that indicate the token's purpose and environment:

warehouse-scanner-prod
inventory-sync-staging
mobile-app-v2
ci-testing

Using Tokens

HTTP Header

Include the token in the Authorization header:

Authorization: Bearer YOUR_API_TOKEN

Full Example

curl -X GET "https://app.stockaj.com/api/v2/items" \
-H "Authorization: Bearer 1|a1b2c3d4e5f6g7h8..." \
-H "Accept: application/json" \
-H "Content-Type: application/json"

JavaScript

const response = await fetch('https://app.stockaj.com/api/v2/items', {
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Accept': 'application/json',
},
});
const data = await response.json();

Python

import requests

response = requests.get(
'https://app.stockaj.com/api/v2/items',
headers={
'Authorization': 'Bearer YOUR_API_TOKEN',
'Accept': 'application/json',
},
)
data = response.json()

PHP

$response = Http::withToken('YOUR_API_TOKEN')
->acceptJson()
->get('https://app.stockaj.com/api/v2/items');

$data = $response->json();

Token Abilities

Control what each token can do with fine-grained abilities:

Read-Only Abilities

AbilityResources
items:readItems, variants, types, tags
renters:readRenters
rents:readRentals
webhooks:readWebhooks
notifications:readNotifications
instance:readWorkspace settings

Write Abilities

AbilityResources
items:createCreate items, variants, types, tags
items:updateUpdate items, variants, types, tags
items:deleteDelete/restore items, variants, types, tags
renters:createCreate renters
renters:updateUpdate renters
renters:deleteDelete/restore renters
rents:createCreate rentals
rents:updateUpdate rentals
rents:deleteDelete rentals

Special Abilities

AbilityPurpose
kiosk:scanUse kiosk scan and search endpoints
webhooks:manageCreate/update/delete webhooks
notifications:manageManage notification state and preferences
instance:manageUpdate workspace settings

Security Best Practices

  1. Principle of least privilege — Only grant the abilities your integration actually needs.
  2. Separate tokens per integration — Use different tokens for different services so you can revoke them independently.
  3. Rotate tokens regularly — Periodically create new tokens and retire old ones.
  4. Never commit tokens — Use environment variables or secret managers.
  5. Use HTTPS only — Tokens are sent in headers; HTTPS prevents interception.
  6. Monitor usage — Review API access patterns and revoke unused tokens.

Error Responses

401 Unauthorized

Token is missing, invalid, or expired:

{
"message": "Unauthenticated."
}

403 Forbidden

Token doesn't have the required ability:

{
"message": "This action is unauthorized."
}

Resolution: Create a new token with the needed abilities, or update the existing token's permissions.