Request an access token
curl --request POST \
--url https://api.staging.payrails.io/auth/token/{clientId} \
--header 'x-api-key: <api-key>'import requests
url = "https://api.staging.payrails.io/auth/token/{clientId}"
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.staging.payrails.io/auth/token/{clientId}', 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.staging.payrails.io/auth/token/{clientId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"x-api-key: <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"
"net/http"
"io"
)
func main() {
url := "https://api.staging.payrails.io/auth/token/{clientId}"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-api-key", "<api-key>")
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.staging.payrails.io/auth/token/{clientId}")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.staging.payrails.io/auth/token/{clientId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjM2MDB9.YLbew8qP_oOG8uY_lYHsLRv8YS5VzXW80gfNV4_KsbMD3R4xkndHjiz2k0YE58Vo2xyZoCI43_EUH0UZBI9pwAkG8kXTwWPNf95ILTvFQnAnnhWFDZUn2A0pB59bfDoEzhJI3_sI0KydqAOpUwM5kAzPWwKre0-da7ds27DngGdy0bQeaqk1TlHr6bHYrq1zn05lI-wm7V3BdHSxSIky-BED27yhDkXsdL55I9DW_-79cmpStRsoWRU2g4ZvOrgjZ5v7GSyALx7QBYEDOjoG4OLiva2jGJ8OI1OBP7iECiWTznpABdNvpwhsFvb4fVWe3pt_nPUM-8YNxNHVHNmheg",
"token_type": "Bearer",
"expires_in": 3600
}{
"errors": [
{
"id": "a24bc325-3929-4d9d-9c08-b3aa532685b7",
"code": "request.malformed",
"detail": "The request has malformed syntax",
"docUrl": "https://docs.payrails.com/docs/resources/error-codes#requestmalformed"
}
]
}{
"errors": [
{
"id": "a24bc325-3929-4d9d-9c08-b3aa532685b7",
"code": "request.unauthorized",
"detail": "The request lacks necessary credentials to perform the specified action",
"docUrl": "https://docs.payrails.com/docs/resources/error-codes#requestunauthorized"
}
]
}Request an access token
Retrieve an access token to authenticate your requests to Payrails’ services, valid for the number of seconds in expires_in, then request a new one.
POST
https://api.staging.payrails.io
/
auth
/
token
/
{clientId}
Request an access token
curl --request POST \
--url https://api.staging.payrails.io/auth/token/{clientId} \
--header 'x-api-key: <api-key>'import requests
url = "https://api.staging.payrails.io/auth/token/{clientId}"
headers = {"x-api-key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.staging.payrails.io/auth/token/{clientId}', 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.staging.payrails.io/auth/token/{clientId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"x-api-key: <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"
"net/http"
"io"
)
func main() {
url := "https://api.staging.payrails.io/auth/token/{clientId}"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("x-api-key", "<api-key>")
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.staging.payrails.io/auth/token/{clientId}")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.staging.payrails.io/auth/token/{clientId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjM2MDB9.YLbew8qP_oOG8uY_lYHsLRv8YS5VzXW80gfNV4_KsbMD3R4xkndHjiz2k0YE58Vo2xyZoCI43_EUH0UZBI9pwAkG8kXTwWPNf95ILTvFQnAnnhWFDZUn2A0pB59bfDoEzhJI3_sI0KydqAOpUwM5kAzPWwKre0-da7ds27DngGdy0bQeaqk1TlHr6bHYrq1zn05lI-wm7V3BdHSxSIky-BED27yhDkXsdL55I9DW_-79cmpStRsoWRU2g4ZvOrgjZ5v7GSyALx7QBYEDOjoG4OLiva2jGJ8OI1OBP7iECiWTznpABdNvpwhsFvb4fVWe3pt_nPUM-8YNxNHVHNmheg",
"token_type": "Bearer",
"expires_in": 3600
}{
"errors": [
{
"id": "a24bc325-3929-4d9d-9c08-b3aa532685b7",
"code": "request.malformed",
"detail": "The request has malformed syntax",
"docUrl": "https://docs.payrails.com/docs/resources/error-codes#requestmalformed"
}
]
}{
"errors": [
{
"id": "a24bc325-3929-4d9d-9c08-b3aa532685b7",
"code": "request.unauthorized",
"detail": "The request lacks necessary credentials to perform the specified action",
"docUrl": "https://docs.payrails.com/docs/resources/error-codes#requestunauthorized"
}
]
}Authorizations
You can use your secret API key in the x-api-key header of your API requests for supported endpoints: x-api-key: <YOUR_API_KEY_HERE>.
API keys are environment specific and should be securely guarded.
You don't have your API key yet? Contact your Payrails account manager.
Path Parameters
The id of the client that wants to retrieve an OAuth token.