Create an API token
Needs permission api-token:write.
Issues a new client credential for your account. The response carries clientSecret exactly once — store it before doing anything else. Retrying with the same Idempotency-Key answers 200 with the token already made and no secret; if the secret has been lost, rotate the token.
roleId is the token’s role (GET /roles, those listing api-token in assignableTo); leave it out for your account’s default role. A token’s role never covers API tokens, roles or the account, whatever it says. Giving a token a role needs a caller who manages API tokens where it applies (403 access_management_denied otherwise; a person or an API token alike), and the role’s permissions must be ones you hold (403 role_assignment_denied). A role for people only answers 400 role_not_assignable, and while only Administrator can be given out any other role answers 400 role_not_yet_available. A role you leave out on access it did not have is your account’s default role (GET /customer/access-settings), and administrator while only Administrator can be given out; when that default role is for people only, the token is refused with 400 role_not_assignable and you name its role. Every response lists the token’s role at each place in roles.
allowedIpRanges lists the address ranges the token may be used from: 1 to 20, IPv4 or IPv6, such as 203.0.113.0/24 or 2001:db8::/32, with no spaces or leading zeros. Each is stored as its network address. From anywhere else every API, this one included, answers 403 ip_not_allowed. 400 invalid_ip_range names a range we cannot use. Only a person changes or lifts an existing token’s ranges: an API token is refused with 403 insufficient_permissions, missingPermission: api-token:write. An API token restricted to ranges issues or rotates only tokens within them (403 token_ranges_wider_than_yours); one it issues without ranges gets its own. Leave it out to allow any address.
State what the token reaches as either organisationIds or allOrganisations: true, never both. allOrganisations grants account-wide access — every organisation the account owns, including ones added later — and only somebody who already holds account-wide access may grant it (403 whole_customer_access_denied otherwise). name is 3 to 100 characters and unique within your account.
An account may hold 5 API tokens, counting every client credential it holds and not only the ones created here. Being over the limit revokes nothing; it only refuses a new one. Three things answer 409, told apart by message.token:
token_limit_reached— the account already holds 5 tokens. Revoke one that is no longer used, or contact support to raise the allowance.duplicate_token_name— another token in your account has that name.idempotency_key_reused— thatIdempotency-Keywas already used for a different request body.
403 billing_not_set_up when billing is not set up for the account yet — email hello@flowpayroll.ai to agree pricing and set it up. Accounts onboarded by Flow Payroll are already set up.
curl --request POST \
--url https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
{
"name": "<string>",
"organisationIds": [
"<string>"
],
"allOrganisations": true,
"access": [
{
"scope": {
"id": "<string>"
},
"roleId": "<string>"
}
],
"allowedIpRanges": [
"<string>"
]
}
'import requests
url = "https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens"
payload = {
"name": "<string>",
"organisationIds": ["<string>"],
"allOrganisations": True,
"access": [
{
"scope": { "id": "<string>" },
"roleId": "<string>"
}
],
"allowedIpRanges": ["<string>"]
}
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
organisationIds: ['<string>'],
allOrganisations: true,
access: [{scope: {id: '<string>'}, roleId: '<string>'}],
allowedIpRanges: ['<string>']
})
};
fetch('https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'organisationIds' => [
'<string>'
],
'allOrganisations' => true,
'access' => [
[
'scope' => [
'id' => '<string>'
],
'roleId' => '<string>'
]
],
'allowedIpRanges' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Auth-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"organisationIds\": [\n \"<string>\"\n ],\n \"allOrganisations\": true,\n \"access\": [\n {\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"roleId\": \"<string>\"\n }\n ],\n \"allowedIpRanges\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Auth-Token", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens")
.header("X-Auth-Token", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"organisationIds\": [\n \"<string>\"\n ],\n \"allOrganisations\": true,\n \"access\": [\n {\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"roleId\": \"<string>\"\n }\n ],\n \"allowedIpRanges\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Auth-Token"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"organisationIds\": [\n \"<string>\"\n ],\n \"allOrganisations\": true,\n \"access\": [\n {\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"roleId\": \"<string>\"\n }\n ],\n \"allowedIpRanges\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": {
"clientId": "<string>",
"name": "<string>",
"clientSecret": "<string>",
"organisationIds": [
"<string>"
],
"coversWholeCustomer": true,
"alreadyExisted": true,
"roleId": "<string>",
"allowedIpRanges": [
"<string>"
],
"access": [
{
"scope": {
"type": "Organisation",
"id": "<string>"
},
"roleId": "<string>"
}
]
},
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": {
"clientId": "<string>",
"name": "<string>",
"clientSecret": "<string>",
"organisationIds": [
"<string>"
],
"coversWholeCustomer": true,
"alreadyExisted": true,
"roleId": "<string>",
"allowedIpRanges": [
"<string>"
],
"access": [
{
"scope": {
"type": "Organisation",
"id": "<string>"
},
"roleId": "<string>"
}
]
},
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}Headers
Your own key for this create, so a retry after a lost response finds what the first attempt made instead of making a second one. Any unique string up to 255 characters; a UUID is the usual choice. Send the same value on every retry of the same request, and a new value for a new one — reusing a key for a different body answers 409 idempotency_key_reused. Keys are remembered for 24 hours. Optional, and a request without one simply has no replay protection.
255Body
Issues a new API token (client credential) for your account.
Deprecated: use access. Deprecated: use access with an Account entry. Give the credential access to every organisation the
account owns, including ones added later,
instead of the ones named in organisationIds. State exactly one of the two. This is the
widest grant this API makes, so only somebody who already holds account-wide access may ask for it.
Was this page helpful?
curl --request POST \
--url https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
{
"name": "<string>",
"organisationIds": [
"<string>"
],
"allOrganisations": true,
"access": [
{
"scope": {
"id": "<string>"
},
"roleId": "<string>"
}
],
"allowedIpRanges": [
"<string>"
]
}
'import requests
url = "https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens"
payload = {
"name": "<string>",
"organisationIds": ["<string>"],
"allOrganisations": True,
"access": [
{
"scope": { "id": "<string>" },
"roleId": "<string>"
}
],
"allowedIpRanges": ["<string>"]
}
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
organisationIds: ['<string>'],
allOrganisations: true,
access: [{scope: {id: '<string>'}, roleId: '<string>'}],
allowedIpRanges: ['<string>']
})
};
fetch('https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'organisationIds' => [
'<string>'
],
'allOrganisations' => true,
'access' => [
[
'scope' => [
'id' => '<string>'
],
'roleId' => '<string>'
]
],
'allowedIpRanges' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Auth-Token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"organisationIds\": [\n \"<string>\"\n ],\n \"allOrganisations\": true,\n \"access\": [\n {\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"roleId\": \"<string>\"\n }\n ],\n \"allowedIpRanges\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Auth-Token", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens")
.header("X-Auth-Token", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"organisationIds\": [\n \"<string>\"\n ],\n \"allOrganisations\": true,\n \"access\": [\n {\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"roleId\": \"<string>\"\n }\n ],\n \"allowedIpRanges\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sandbox.flowpayroll.ai/v1/administration/api-tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Auth-Token"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"organisationIds\": [\n \"<string>\"\n ],\n \"allOrganisations\": true,\n \"access\": [\n {\n \"scope\": {\n \"id\": \"<string>\"\n },\n \"roleId\": \"<string>\"\n }\n ],\n \"allowedIpRanges\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": {
"clientId": "<string>",
"name": "<string>",
"clientSecret": "<string>",
"organisationIds": [
"<string>"
],
"coversWholeCustomer": true,
"alreadyExisted": true,
"roleId": "<string>",
"allowedIpRanges": [
"<string>"
],
"access": [
{
"scope": {
"type": "Organisation",
"id": "<string>"
},
"roleId": "<string>"
}
]
},
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": {
"clientId": "<string>",
"name": "<string>",
"clientSecret": "<string>",
"organisationIds": [
"<string>"
],
"coversWholeCustomer": true,
"alreadyExisted": true,
"roleId": "<string>",
"allowedIpRanges": [
"<string>"
],
"access": [
{
"scope": {
"type": "Organisation",
"id": "<string>"
},
"roleId": "<string>"
}
]
},
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}{
"message": {
"text": "<string>",
"token": "<string>",
"tokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
},
"content": {
"data": "<unknown>",
"metadata": {
"dateFormat": "<string>",
"dateTimeFormat": "<string>",
"paginationToken": "<string>"
}
},
"validationIssues": [
{
"field": "<string>",
"reason": "<string>",
"reasonToken": "<string>",
"reasonTokenArguments": [
{
"name": "<string>",
"value": "<unknown>"
}
]
}
]
}