These steps take you from a new key to your first read of your services.
They run against the sandbox, where nothing reaches a
carrier and nothing is billed. The same calls work in production with a
production key and https://api.checknetworks.tools/v2.
Before you start
- Get a sandbox. An Owner or Admin chooses Create Sandbox under Company Settings, then Integrations, then API Keys in the production portal, then Open Sandbox to sign in to it. See The API sandbox.
- Create a key in the sandbox portal, under Company Settings, then
Integrations, then API Keys, with the
data:readscope. Copy the Client ID and the Client Secret. The secret is shown once, and a sandbox one startscn_test_. See API Keys and Scopes. - Keep them in your shell, so every example below runs as it is:
export CN_BASE=https://api.checknetworks.dev/v2
export CN_CLIENT_ID=your-client-id
export CN_CLIENT_SECRET=your-client-secret
The curl examples use jq to read the token out of the answer.
1. Get a token
Ask POST /oauth/token for a token with the scopes you need, here
data:read:
TOKEN=$(curl -s "$CN_BASE/oauth/token" \
-d grant_type=client_credentials \
-d client_id="$CN_CLIENT_ID" \
-d client_secret="$CN_CLIENT_SECRET" \
-d scope=data:read | jq -r .access_token)
The answer, before jq takes the token out of it:
{
"token_type": "Bearer",
"expires_in": 3600,
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI5ZDZiMmMx...",
"scope": "data:read"
}
scope is what the token can really do. A scope the key isn’t allowed is
left out, not refused. The token lasts an hour, and expires_in is in
seconds. Reuse it until then, and ask for a new one when it runs out.
2. Check the token
Send the token on every call as Authorization: Bearer <token>. GET /ping
says which key and account answered and what the token carries:
curl -s "$CN_BASE/ping" -H "Authorization: Bearer $TOKEN"
{
"result": {
"keyId": "9d6b2c1e-4f3a-4b8e-9c2d-1a7e5f3b8c40",
"name": "Quick start",
"scopes": ["data:read"],
"accountId": "840100",
"ip": "203.0.113.10",
"ipAllowlistActive": false,
"environment": "sandbox",
"tokenExpiresAt": "2026-11-21T03:00:00+00:00"
}
}
Your ids, address and times are your own. environment is sandbox here
and live in production. When a later call is refused, call GET /ping
first: it shows the scopes and the address we saw.
3. List your data services
GET /data/services lists your NBN and Opticomm services:
curl -s "$CN_BASE/data/services" -H "Authorization: Bearer $TOKEN"
A new sandbox has no services yet, so the list is empty:
{
"total": 0,
"page": 1,
"perPage": 50,
"results": []
}
Once a connect you order in the sandbox completes, its service is listed here. Data services covers qualifying an address and ordering, and Paging through lists how to read past the first page.
The same in PHP, Python and JavaScript
Each script makes the three calls above, reading the same environment variables.
PHP
With Guzzle (composer require guzzlehttp/guzzle):
<?php
require 'vendor/autoload.php';
$base = getenv('CN_BASE');
$http = new GuzzleHttp\Client();
// 1. Get a token.
$token = json_decode((string) $http->post("{$base}/oauth/token", [
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => getenv('CN_CLIENT_ID'),
'client_secret' => getenv('CN_CLIENT_SECRET'),
'scope' => 'data:read',
],
])->getBody(), true)['access_token'];
$headers = ['Authorization' => "Bearer {$token}", 'Accept' => 'application/json'];
// 2. Check the token.
$ping = json_decode((string) $http->get("{$base}/ping", ['headers' => $headers])->getBody(), true);
echo $ping['result']['environment'], "\n"; // sandbox
// 3. List your data services.
$services = json_decode((string) $http->get("{$base}/data/services", ['headers' => $headers])->getBody(), true);
echo $services['total'], "\n"; // 0 on a new sandbox
Python
With Requests (pip install requests):
import os
import requests
base = os.environ["CN_BASE"]
# 1. Get a token.
token = requests.post(f"{base}/oauth/token", data={
"grant_type": "client_credentials",
"client_id": os.environ["CN_CLIENT_ID"],
"client_secret": os.environ["CN_CLIENT_SECRET"],
"scope": "data:read",
}).json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
# 2. Check the token.
ping = requests.get(f"{base}/ping", headers=headers).json()
print(ping["result"]["environment"]) # sandbox
# 3. List your data services.
services = requests.get(f"{base}/data/services", headers=headers).json()
print(services["total"]) # 0 on a new sandbox
JavaScript
With Node 18 or later, which has fetch built in. Save it as
quick-start.mjs and run node quick-start.mjs:
const base = process.env.CN_BASE;
// 1. Get a token.
const tokenResponse = await fetch(`${base}/oauth/token`, {
method: 'POST',
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.CN_CLIENT_ID,
client_secret: process.env.CN_CLIENT_SECRET,
scope: 'data:read',
}),
});
const { access_token: token } = await tokenResponse.json();
const headers = { Authorization: `Bearer ${token}`, Accept: 'application/json' };
// 2. Check the token.
const ping = await (await fetch(`${base}/ping`, { headers })).json();
console.log(ping.result.environment); // sandbox
// 3. List your data services.
const services = await (await fetch(`${base}/data/services`, { headers })).json();
console.log(services.total); // 0 on a new sandbox
In Postman
The same steps take no code in Postman:
- Import the collection and the sandbox environment, and choose Check Networks Sandbox as the environment.
- Fill in the environment. Set
clientIdandclientSecretto your sandbox key’s Client ID and Client Secret, in place of the placeholders.scopeisdata:read. Set it to the scopes you need, space-separated. - Send Check Your Token, which is
GET /ping, under Wholesale Account, then Authentication. The collection asksPOST /oauth/tokenfor a token before the first request, and for a new one before it expires, so you never paste one in. Request an Access Token, the first request, gets one by hand.
Every call in the reference is in the collection, in the reference’s
groups, with its example values filled in. Every write that takes an
Idempotency-Key sends a new one each time you send it. For production,
import the
production environment
and fill in a production key. Every call then runs against your real
account.
If a call is refused
Every error has the same body, with a code to branch on and a docUrl
to what it means.
| The API answers | What it means |
|---|---|
401 |
The token is missing or has run out. Ask for a new one. |
403 missing_scope |
The token doesn’t carry the scope the call needs. |
See API errors.
Next steps
- Webhooks: have events sent to you instead of asking.
- Retrying writes safely: the
Idempotency-Keyevery carrier write needs. - API errors: every error code and what to do about it.
- API rate limits: the limits, the headers that say where you stand, and backing off.
- Paging through lists: reading a list to the end, and the CSV and NDJSON downloads.
- The full reference, at api.checknetworks.tools/docs.