> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.stafflion.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.stafflion.com/_mcp/server.

# Access Token

POST https://auth.stafflion.com/oauth/token
Content-Type: application/json

Request an access token with the client ID and secret Stafflion issued for the environment. Send the token as a Bearer token on every other request. The token lasts 24 hours.

Reference: https://developers.stafflion.com/api/api-reference/authentication/access-token

## Request

### Body (application/json)

This endpoint expects an object.

- `client_id` (string, required) — Partner unique client ID.
- `audience` (string, required) — Target API audience. Staging: `https://staging.stafflion.com/api/v1`. Production: `https://app.stafflion.com/api/v1`.
- `grant_type` (string, required) — Must be `client_credentials`.
- `client_secret` (string, required) — Partner unique client secret.

## Response

### 200

OK

- `expires_in` (integer, required) — Token lifetime in seconds. `86400` = 24 hours.
- `token_type` (string, required) — Always `Bearer`.
- `access_token` (string, required) — JWT. Send as `Authorization: Bearer <access_token>`.

## Errors

### 401 Unauthorized Error

Invalid client ID or secret. Illustrative body, confirm against staging.

- `error` (string, required) — OAuth error code.
- `error_description` (string, required) — Human-readable description.

### 422 Unprocessable Entity Error

Validation failed. A required field is missing.

- `message` (string, required) — Human-readable reason.
- `code` (string, required) — Stable error code, `validation_failed` for invalid input.
- `url` (string, optional) — Request path, when the error comes from input validation.
- `errors` (map from string to list of string, optional) — Optional. Invalid fields, each with a list of messages.

## Examples

### Staging (primary environment)

**Request**

```json
{
  "client_id": "YOUR_STAGING_CLIENT_ID",
  "audience": "https://staging.stafflion.com/api/v1",
  "grant_type": "client_credentials",
  "client_secret": "YOUR_STAGING_CLIENT_SECRET"
}
```

**Response**

```json
{
  "expires_in": 86400,
  "token_type": "Bearer",
  "access_token": "ACCESS_TOKEN"
}
```

**SDK Code**

```python Staging (primary environment)
import requests

url = "https://auth.stafflion.com/oauth/token"

payload = {
    "client_id": "YOUR_STAGING_CLIENT_ID",
    "audience": "https://staging.stafflion.com/api/v1",
    "grant_type": "client_credentials",
    "client_secret": "YOUR_STAGING_CLIENT_SECRET"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Staging (primary environment)
const url = 'https://auth.stafflion.com/oauth/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"client_id":"YOUR_STAGING_CLIENT_ID","audience":"https://staging.stafflion.com/api/v1","grant_type":"client_credentials","client_secret":"YOUR_STAGING_CLIENT_SECRET"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Staging (primary environment)
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://auth.stafflion.com/oauth/token"

	payload := strings.NewReader("{\n  \"client_id\": \"YOUR_STAGING_CLIENT_ID\",\n  \"audience\": \"https://staging.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_STAGING_CLIENT_SECRET\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Staging (primary environment)
require 'uri'
require 'net/http'

url = URI("https://auth.stafflion.com/oauth/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"client_id\": \"YOUR_STAGING_CLIENT_ID\",\n  \"audience\": \"https://staging.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_STAGING_CLIENT_SECRET\"\n}"

response = http.request(request)
puts response.read_body
```

```java Staging (primary environment)
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://auth.stafflion.com/oauth/token")
  .header("Content-Type", "application/json")
  .body("{\n  \"client_id\": \"YOUR_STAGING_CLIENT_ID\",\n  \"audience\": \"https://staging.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_STAGING_CLIENT_SECRET\"\n}")
  .asString();
```

```php Staging (primary environment)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://auth.stafflion.com/oauth/token', [
  'body' => '{
  "client_id": "YOUR_STAGING_CLIENT_ID",
  "audience": "https://staging.stafflion.com/api/v1",
  "grant_type": "client_credentials",
  "client_secret": "YOUR_STAGING_CLIENT_SECRET"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Staging (primary environment)
using RestSharp;

var client = new RestClient("https://auth.stafflion.com/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"client_id\": \"YOUR_STAGING_CLIENT_ID\",\n  \"audience\": \"https://staging.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_STAGING_CLIENT_SECRET\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Staging (primary environment)
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "client_id": "YOUR_STAGING_CLIENT_ID",
  "audience": "https://staging.stafflion.com/api/v1",
  "grant_type": "client_credentials",
  "client_secret": "YOUR_STAGING_CLIENT_SECRET"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://auth.stafflion.com/oauth/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Production

**Request**

```json
{
  "client_id": "YOUR_PRODUCTION_CLIENT_ID",
  "audience": "https://app.stafflion.com/api/v1",
  "grant_type": "client_credentials",
  "client_secret": "YOUR_PRODUCTION_CLIENT_SECRET"
}
```

**Response**

```json
{
  "expires_in": 86400,
  "token_type": "Bearer",
  "access_token": "ACCESS_TOKEN"
}
```

**SDK Code**

```python Production
import requests

url = "https://auth.stafflion.com/oauth/token"

payload = {
    "client_id": "YOUR_PRODUCTION_CLIENT_ID",
    "audience": "https://app.stafflion.com/api/v1",
    "grant_type": "client_credentials",
    "client_secret": "YOUR_PRODUCTION_CLIENT_SECRET"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Production
const url = 'https://auth.stafflion.com/oauth/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"client_id":"YOUR_PRODUCTION_CLIENT_ID","audience":"https://app.stafflion.com/api/v1","grant_type":"client_credentials","client_secret":"YOUR_PRODUCTION_CLIENT_SECRET"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Production
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://auth.stafflion.com/oauth/token"

	payload := strings.NewReader("{\n  \"client_id\": \"YOUR_PRODUCTION_CLIENT_ID\",\n  \"audience\": \"https://app.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_PRODUCTION_CLIENT_SECRET\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Production
require 'uri'
require 'net/http'

url = URI("https://auth.stafflion.com/oauth/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"client_id\": \"YOUR_PRODUCTION_CLIENT_ID\",\n  \"audience\": \"https://app.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_PRODUCTION_CLIENT_SECRET\"\n}"

response = http.request(request)
puts response.read_body
```

```java Production
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://auth.stafflion.com/oauth/token")
  .header("Content-Type", "application/json")
  .body("{\n  \"client_id\": \"YOUR_PRODUCTION_CLIENT_ID\",\n  \"audience\": \"https://app.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_PRODUCTION_CLIENT_SECRET\"\n}")
  .asString();
```

```php Production
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://auth.stafflion.com/oauth/token', [
  'body' => '{
  "client_id": "YOUR_PRODUCTION_CLIENT_ID",
  "audience": "https://app.stafflion.com/api/v1",
  "grant_type": "client_credentials",
  "client_secret": "YOUR_PRODUCTION_CLIENT_SECRET"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Production
using RestSharp;

var client = new RestClient("https://auth.stafflion.com/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"client_id\": \"YOUR_PRODUCTION_CLIENT_ID\",\n  \"audience\": \"https://app.stafflion.com/api/v1\",\n  \"grant_type\": \"client_credentials\",\n  \"client_secret\": \"YOUR_PRODUCTION_CLIENT_SECRET\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Production
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "client_id": "YOUR_PRODUCTION_CLIENT_ID",
  "audience": "https://app.stafflion.com/api/v1",
  "grant_type": "client_credentials",
  "client_secret": "YOUR_PRODUCTION_CLIENT_SECRET"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://auth.stafflion.com/oauth/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```