Authentication
Choose between OAuth2 tokens, JWTs, and API keys, and learn how each one works.
Every endpoint except GET /version and the token endpoints themselves requires authentication. Whichever method you use, send the credential as a bearer token:
Authorization: Bearer YOUR_TOKENChoosing a method
| Method | Best for | Get it from | Lifetime |
|---|---|---|---|
| JWT | Apps where a user signs in | POST /jwt | Short-lived; renew with the refresh JWT |
| OAuth2 access token | Apps where a user signs in | POST /tokens | Short-lived (expires_in seconds); renew with the refresh token |
| API key | Server-to-server integrations with no user signing in | POST /apikeys (restricted) | Long-lived until revoked |
JWTs and OAuth2 access tokens come from the same sign-in: your application's client ID and secret, plus a user's username and password. The same client credentials work for both. Two things only JWTs offer:
- Delegated access: an API key can create a JWT for a specific user, without that user's password. See Delegated access.
- Targeted revocation: you can revoke a single JWT, or every JWT for a user.
Otherwise, pick whichever suits your stack. API keys work differently, as the next section explains.
OAuth2 client credentials vs. API keys
These two are easy to confuse, because both involve a long secret string your application stores. They answer different questions:
- A client ID and client secret identify your application. On their own, they don't grant access to anything. To get a token, your application must also send a user's username and password. The token then acts as that user, with that user's permissions.
- An API key identifies an integration. It is a credential in its own right: no user signs in, and its permissions are fixed when the key is created.
There is no machine-only OAuth2 flowThe Level365 API supports the
password,refresh_token, andmfagrant types. It doesn't support the OAuth2client_credentialsgrant, so a client ID and secret can't be used alone for machine-to-machine access. If your integration has to store a user's password just to get tokens, it should use an API key instead.
| OAuth2 client (client ID + secret) | API key | |
|---|---|---|
| Identifies | Your application | The integration itself |
| Requires a user's password | Yes, for every new sign-in | No |
| Permissions | Those of the user who signed in | The scope set on the key when it was created |
| Lifetime | Short-lived tokens, renewed with a refresh token | Until the key is revoked |
| Extra restrictions | — | IP allowlist, read-only, allowed models, limited to a reseller, domain, or user |
| Audit trail | Actions are attributed to the signed-in user | Each key has a key-id, a description, and a last-used time |
| Typical uses | Custom portals, softphone or CRM integrations where each person signs in, mobile apps | Billing, provisioning, reporting, event subscriptions, other backend automation |
Which should I use?
- People sign in to your app and act as themselves: use OAuth2 or JWT. Each user's own scope limits what the app can do on their behalf.
- A backend job runs with no person present: use an API key with the narrowest scope that works.
- A backend service needs to act as specific users (for example, placing calls or reading voicemail for one user): use an API key to create a delegated JWT for that user. No user password is needed.
- Long-running event subscriptions: create them with an API key. Subscriptions created with a short-lived token expire with that token. See Event Subscriptions.
Can I use just the client ID and secret, without a user?
No. Every token request also requires a user's username and password. For access without a user, use an API key.
Should my integration sign in as a shared 'service' user?
Avoid it. Storing a user's password means the integration breaks when the password changes or MFA is turned on, and its actions are attributed to that user. An API key gives the integration its own credential, scope, and audit trail.
Is an API key a kind of OAuth2 token?
No. Both are sent the same way, in the Authorization: Bearer header, but an API key isn't issued through OAuth2 and doesn't expire or need refreshing.
Getting credentialsRequest an API key for your integration, or a client ID and client secret for your application, from Level365. See Requesting API Access for what to include.
JWT
Create a JWT
curl -X POST https://api.365sip.com/ns-api/v2/jwt \
-H "Content-Type: application/json" \
-d '{
"grant_type": "password",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"username": "1001@yourdomain",
"password": "YOUR_PASSWORD"
}'The response contains two JWTs:
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}tokenis the JWT you send as the bearer token.refreshcan only be used to get a new JWT. It can't authenticate other requests.
The username is usually the user's UID (user@domain), but it may be an email address or another login, depending on how the user is set up.
Refresh a JWT
When the JWT expires, exchange the refresh JWT for a new pair:
curl -X POST https://api.365sip.com/ns-api/v2/jwt \
-H "Content-Type: application/json" \
-d '{ "refresh": "YOUR_REFRESH_JWT" }'Each refresh JWT can be used once. It's revoked when used, and the response includes a new one.
To see when a JWT expires, call GET /jwt. The exp claim is the expiry time (Unix seconds), and time_out is the token's total lifetime in milliseconds. Refresh shortly before exp rather than waiting for a 401.
Inspect or revoke JWTs
| Request | What it does |
|---|---|
GET /jwt | Read the claims in the current JWT |
DELETE /jwt | Revoke the current JWT |
DELETE /jwt/{uid} | Revoke every JWT for a user (user@domain), or a single JWT by its JTI (JWT ID) |
Delegated access
An integration authenticated with an API key can create a JWT for another user by sending just the user and domain. The response has the same token and refresh pair as a normal sign-in, and the JWT acts as that user, with that user's scope:
curl -X POST https://api.365sip.com/ns-api/v2/jwt \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "user": "1001", "domain": "yourdomain" }'OAuth2 access token
Request a token
curl -X POST https://api.365sip.com/ns-api/v2/tokens \
-H "Content-Type: application/json" \
-d '{
"grant_type": "password",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"username": "1001@yourdomain",
"password": "YOUR_PASSWORD"
}'The response includes the token and details about the signed-in user:
{
"access_token": "2711618e692064e183e9596a26e8eb10",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "a8c5ee5bd2f5b66e2c3dd91ad8e0c3f1",
"scope": "Office Manager",
"uid": "1001@yourdomain",
"domain": "yourdomain",
"user": "1001",
"apiversion": "45.1.2"
}Refresh a token
curl -X POST https://api.365sip.com/ns-api/v2/tokens \
-H "Content-Type: application/json" \
-d '{
"grant_type": "refresh_token",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"refresh_token": "YOUR_REFRESH_TOKEN"
}'Multi-factor authentication (MFA)
Signing in a user who has MFA enabled
If the user has MFA enabled, signing in takes two requests. This works the same way for POST /tokens and POST /jwt.
- Send the username and password as usual. Instead of a usable token, the response tells you MFA is required and includes
mfa_type,mfa_vendor, and anaccess_tokenfor the second step. - Send the passcode. Repeat the request with
grant_typeset tomfa, copymfa_type,mfa_vendor, andaccess_tokenfrom the first response, and add the user's 6-digitpasscodefrom their authenticator app:
{
"grant_type": "mfa",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"username": "1001@yourdomain",
"password": "YOUR_PASSWORD",
"mfa_type": "authenticator",
"mfa_vendor": "google",
"ns_id_type": "subscriber",
"passcode": "123456",
"access_token": "TOKEN_FROM_STEP_1"
}Leave ns_id_type as subscriber for API and portal sign-ins.
API keys
API keys are for integrations that run without a user signing in, such as billing or provisioning automation.
RestrictedCreating API keys requires special access. Contact Level365 if your integration needs one.
When an API key is created, its access is defined by:
| Setting | What it does |
|---|---|
user-scope | The permission level the key operates with |
reseller, domain, user | Restrict the key to that part of the platform |
readonly | When yes, the key can only make GET requests |
ip-address | Allow requests only from listed IPs or subnets, comma-separated (for example 1.2.3.4,5.6.7.0/24) |
allowed-models | Limit which kinds of data the key can access |
can-create-keys | When yes, the key can create other keys with a lower scope than its own |
description | A clear name for what the key is used for (at least 12 characters) |
The response includes a key-id, used to manage and audit the key, and the key itself.
Limiting a key to specific data
By default, a key can use every kind of data its scope allows. Use allowed-models to narrow it to only what the integration needs. For example, an SMS alerting integration only needs messaging:
{
"description": "SMS alerts from our monitoring system",
"reseller": "YOUR_RESELLER",
"domain": "demo.level365",
"user-scope": "Office Manager",
"allowed-models": ["message", "messagesession"],
"readonly": "no",
"can-create-keys": "no"
}allowed-models takes a single model name, an array of names, or * for all. The names come from the API's permission definitions, so they don't always match endpoint paths. Some common ones:
| Integration | Models |
|---|---|
| Messaging | message, messagesession, smsnumber |
| Call history | cdr |
| Call recordings | recording |
| Voicemail | voicemail |
| Presence | presence |
The full list is in the allowed-models field of Create API Key. Combine allowed-models with readonly and ip-address for the tightest restriction. Check what a key can do at any time with GET /apikeys/~.
Save the key immediatelyThe
keyvalue is only shown once. Store it securely; if it's lost, revoke the key and create a new one.
To manage keys:
| Request | What it does |
|---|---|
GET /apikeys/~ | Read details of the key making the request, including its scope |
GET /apikeys | List keys under your account |
PUT /apikeys/{key_id} | Update a key |
DELETE /apikeys/{key_id} | Revoke a key |
User scopes
Every token and API key operates with a user scope that determines what it can read and change. From least to most access:
| Scope | Typical access |
|---|---|
| Basic User, Simple User, Advanced User | The user's own settings, voicemail, contacts, and calls |
| Call Center Agent | Their own user, plus agent actions in call queues |
| Call Center Supervisor | Call queues, agents, and call center statistics |
| Site Manager | Users and resources within their site |
| Office Manager | Users and resources across their domain |
| Reseller | All domains belonging to the reseller |
| Super User | The entire platform |
Requests outside your scope return 403 Forbidden. Some endpoints and filters, such as * for all domains, require Super User.
Security best practices
- Keep client secrets, refresh tokens, and API keys on your server, never in browser or mobile app code.
- Give API keys the narrowest scope that works. Use
readonlyand IP restrictions where you can. - Refresh tokens before they expire instead of storing user passwords.
- Revoke tokens and keys you no longer need, and review
lastused-datetimeto find unused keys.
Updated 10 days ago
