Reference
API keys and permissions
Choose the right payment API key, get it safely, and give it only the permissions it needs.
Two kinds of key
| API v1 | API v2 | |
|---|---|---|
| Used for | Checkout, and getting one payment | Links, invoices, payments, reports, settings and stores |
| Where to get it | Dashboard Settings, then API | Ask for it, then approve it in your browser |
| Starts with | Nothing special | swk_dev_ or swk_main_ |
| Permissions | Cannot be changed | You choose them |
You can't use one kind in place of the other. Each key is for one account and one network, so there is no network setting to send.
Send your key with every request:
Authorization: Bearer YOUR_API_KEYKeep every key on your server
Get an API v2 key
You need Node.js 22 or later. Save this as connect.mjs. It saves your new key in a file that only your user account can read (on macOS and Linux), and never shows the key.
// Gets an API v2 key, and saves it in a file without showing it.
// Usage: node connect.mjs FILE PERMISSION...
import { existsSync } from "node:fs";
import { writeFile } from "node:fs/promises";
const API = process.env.SWITRO_API_URL ?? "https://www.switro.com/api";
const [file, ...scopes] = process.argv.slice(2);
if (!file || !scopes.length) throw new Error("Usage: node connect.mjs FILE PERMISSION...");
if (existsSync(file)) throw new Error(`${file} already exists. Choose another file.`);
async function post(path, body) {
const response = await fetch(`${API}/v2/device/${path}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const data = await response.json();
if (!response.ok) throw new Error(`Switro answered ${response.status}: ${data.message}`);
return data;
}
const request = await post("authorize", {
client_name: "My website",
// "devnet" is for testing. "mainnet" uses real money.
network: "devnet",
scopes,
});
console.log(`1. Open ${request.verification_uri} and sign in.`);
console.log(`2. Enter this code: ${request.user_code}`);
console.log("3. Check the network and permissions, then approve.");
let answer = { status: "pending" };
while (answer.status === "pending") {
await new Promise((resolve) => setTimeout(resolve, request.interval * 1000));
answer = await post("token", { device_code: request.device_code });
}
if (answer.status !== "approved") throw new Error(`The request was ${answer.status}. Start again.`);
// Only your user account can read this file. Never add it to git.
await writeFile(file, `SWITRO_API_KEY=${answer.api_key}\n`, { flag: "wx", mode: 0o600 });
console.log(`Connected. The key is saved in ${file}.`);Run it with a file name and the permissions you need. For example:
node connect.mjs links.env links:read links:writeOpen the address it gives you, sign in and enter the code. Check the network and permissions before you approve.

Only enter a code that you asked for
The sample uses devnet. For a live website, change network to "mainnet", and save that key in a different file.
How the connection works
| Field | Required | What it is |
|---|---|---|
client_name | Yes | Your app's name, up to 60 characters. The user sees it |
network | No | devnet (the default) or mainnet |
scopes | No | A list of permissions. If you leave it out, you get all of them except the two that must be asked for by name |
The answer has device_code, user_code, verification_uri, expires_in and interval. Show the user the address and user_code, and keep device_code private.
device_code. Wait at least interval seconds (5) between requests.| Status | What to do |
|---|---|
pending | Wait, then ask again |
approved | Save api_key. It is only given once |
denied | Stop. The user refused |
expired | Start again. A request lasts 10 minutes, and its key can only be collected once |
An API key cannot approve a connection or create another key. Only someone who is signed in can.
Permissions
Only ask for what you need. The user can approve fewer, but never more.
| Permission | What it allows | Must be asked for by name |
|---|---|---|
config:read | See your payment settings and payout wallets | No |
config:write | Change your payment settings, but not payout wallets | Yes |
customers:read | See your store's customer list, with names and emails | Yes |
invoices:read | See invoices and customer details on them | No |
invoices:write | Create and void invoices | No |
links:read | See payment links | No |
links:write | Create payment links | No |
orders:read | See store orders and delivery details | No |
orders:write | Create, update and cancel store orders | No |
payments:read | See payments and details customers entered | No |
reports:read | See sales reports | No |
store:read | See your store, products and stock | No |
store:write | Change and publish your store, products, prices and stock | No |
No key can change where you get paid
