Skip to main content
The API accepts two kinds of credential. Both go in the same header.
Product API keys are on the NervesHub main branch but in no tagged release as of NervesHub 2.5.4. An instance running 2.5.4 or earlier only accepts user access tokens.

Send the credential

Put the token or key in the Authorization header with the Bearer scheme.
The server also accepts the scheme token in place of Bearer. The scheme name is not case sensitive.

User access tokens

A user access token acts as you.

Create a token

1

Open your access tokens

Open the user menu and select Access tokens.
2

Create the token

Click New token. Enter a Note that says what the token is for, then click Create access token.
3

Copy it

Copy the token shown under New Token. It is not shown again.
The list shows each token’s note and when it was last used. Click Delete to revoke a token. Anything using it stops working.

Check a token

Product API keys

A product API key is a credential for automation that has no person’s account behind it. It works on one product only, holds a role of its own, and keeps working when the person who created it leaves the organization.
Product API keys are on the NervesHub main branch but in no tagged release as of NervesHub 2.5.4.

Create a key

You need permission to edit the product’s settings. The built-in Manage and Admin roles have it.
1

Open the product's API keys

In the product, open Product settings and select the API keys tab.
2

Create the key

Click Create key. Enter a Name, which is shown in the key list and in the audit log. Choose a Role, then click Create key.
3

Copy it

Copy the key from the dialog, then click I’ve copied it. Only a hash of the key is stored, so it cannot be shown again. If you lose it, deactivate it and create another.

Choose a role

A key holds one role, which decides what it may do, the same way a member’s role does.
  • The built-in roles on offer are View and Manage. Admin is not offered, because what it adds is running the organization, which no key can reach.
  • A key can hold one of the organization’s custom roles instead. See Roles.
  • You can only give a key a role that grants nothing beyond your own role.
Uploading firmware and creating releases both need Manage, or a custom role with the Upload firmware and Create, edit and approve releases permissions.

What a key can reach

A key works on these routes for its own product:
  • Everything under /api/orgs/{org_name}/products/{product_name}/, including devices, firmware, archives, deployment groups, releases and support scripts.
  • GET /api/orgs/{org_name}/products/{product_name} to read the product.
  • /api/devices/{identifier} and its sub-routes, for devices in the product.
  • The event stream socket.
A key cannot reach anything about a user or a whole organization, and it cannot change the product itself. These return 401:
  • /api/users/me and /api/orgs
  • /api/orgs/{org_name}/users, /keys, /ca_certificates, /webhooks and /iroh_endpoints
  • Listing, creating, updating or deleting products
A request that names any other organization or product returns 404. A key cannot open a remote console or shell. The console socket accepts user access tokens only.

Deactivate a key

In the API keys tab, click Deactivate on the key’s row, then Deactivate key.
  • API requests with the key are refused at once.
  • Any event stream socket opened with the key is disconnected.
  • Deactivation cannot be undone. The key stays in the list, marked deactivated.
The Last used column shows when a key last authenticated, to the nearest minute. Check it before you deactivate a key.

Use a credential with the CLI

nh sends whatever is in --token or NERVES_HUB_TOKEN as the bearer token, so both kinds of credential work.
With a product API key, only commands that use the routes listed above work. nh user whoami, nh org, nh key, nh ca, nh webhook and nh device console need a user access token. See CI and automation for a complete pipeline setup.

Failed authentication