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

# Create payee session token

POST https://api.useroot.com/api/session-tokens
Content-Type: application/json

Generate a session token for frontend use.

This endpoint can only be called with an API token context.
It generates a short-lived JWT token with specific scopes for managing payment methods.

The process:
1. API token authenticates the request
2. Payee ID is provided in the request
3. System validates the payee ID belongs to the API token's root entity
4. A session token is created containing the payee's ID, root entity ID, and manage payment methods scopes

This allows frontend applications to make authenticated requests on behalf of a specific payee.

Reference: https://useroot.docs.buildwithfern.com/api-reference/session-tokens-api/create-payee-session-token

## Authentication

- `x-api-key` header (required) — RootPay API key sent in the x-api-key header. Keys are environment-scoped: live_* for production, test_* for sandbox.

## Request

### Body (application/json)

- `payee_id` (string, required) — UUID of the payee to create a token for. This will be used as the user identifier in the token.

## Response

### 200

Successful Response

- `token` (string, required) — JWT token to be used for further requests
- `expires_in_seconds` (integer, required) — Number of seconds until this token expires
- `scopes` (list of string, required) — Permission scopes granted to this token

## Examples

**Request**

```json
{
  "payee_id": "string"
}
```

**Response**

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_in_seconds": 36000,
  "scopes": [
    "list_methods",
    "add_method",
    "set_default",
    "delete_method",
    "view_payee"
  ]
}
```

**SDK Code**

```python Legacy payee session token response
import requests

url = "https://api.useroot.com/api/session-tokens"

payload = { "payee_id": "string" }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Legacy payee session token response
const url = 'https://api.useroot.com/api/session-tokens';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"payee_id":"string"}'
};

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

```go Legacy payee session token response
package main

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

func main() {

	url := "https://api.useroot.com/api/session-tokens"

	payload := strings.NewReader("{\n  \"payee_id\": \"string\"\n}")

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

	req.Header.Add("x-api-key", "<apiKey>")
	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 Legacy payee session token response
require 'uri'
require 'net/http'

url = URI("https://api.useroot.com/api/session-tokens")

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

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"payee_id\": \"string\"\n}"

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

```java Legacy payee session token response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.useroot.com/api/session-tokens")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"payee_id\": \"string\"\n}")
  .asString();
```

```php Legacy payee session token response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.useroot.com/api/session-tokens', [
  'body' => '{
  "payee_id": "string"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Legacy payee session token response
using RestSharp;

var client = new RestClient("https://api.useroot.com/api/session-tokens");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"payee_id\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Legacy payee session token response
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["payee_id": "string"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.useroot.com/api/session-tokens")! 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()
```