Skip to main content
The NervesHub API uses Bearer token authentication — you generate a personal access token once and include it in the Authorization header of every request. Tokens are scoped to your user account and carry your organization permissions.

Get a Token

You can obtain a token in two ways: via the nh CLI or from the NervesCloud web UI.
Authenticate with the CLI to generate and store a token locally:
This opens a browser flow on your NervesHub instance. After you confirm the session, the CLI stores your token automatically for subsequent commands.

Use the Token

Pass the token as a Bearer credential in the Authorization header of every API request:
Replace YOUR_TOKEN with your actual token value.

Store the Token as an Environment Variable

Rather than embedding your token in every command, export it as an environment variable. Both the CLI and shell scripts can read from it:
The nh CLI reads NERVES_HUB_TOKEN (or NH_TOKEN) automatically, so authenticated commands need no additional flags:
For curl and scripts, reference the variable in the header:

Verify Authentication

Confirm your token is valid by calling the /api/users/me endpoint:
A successful response returns your user profile:
If the token is missing or invalid, the API returns a 401 error:

Error Responses

A 403 usually means your organization role is too low for the operation rather than that the token is bad. Read-only calls need view; creating or changing resources needs manage; organization settings, member management, and certificate authorities need admin.
For CI/CD pipelines, set NERVES_HUB_NON_INTERACTIVE=true alongside NERVES_HUB_TOKEN to prevent the CLI from prompting for input. The CLI will use the token from the environment and fail fast on auth errors rather than waiting for user interaction.