> This page is for Paperwork API, version v2.
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.cloudraker.com/paperwork/v1/llms.txt

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

# Exchange a token

POST https://your-org.cloudraker.run/v2/oauth/token
Content-Type: application/x-www-form-urlencoded

Exchanges a JWT from a trusted issuer for an opaque `crt_` token. The JWT is the credential, so the route takes no bearer token. Errors have the RFC 6749 shape.

Reference: https://docs.cloudraker.com/paperwork/v2/api/authentication/token

## Request

### Body (application/x-www-form-urlencoded)

This endpoint expects an OAuthTokenRequest.

- `grant_type` (enum, required) — RFC 8693 token exchange or the RFC 7523 JWT bearer grant.
  - Allowed values: `urn:ietf:params:oauth:grant-type:token-exchange`, `urn:ietf:params:oauth:grant-type:jwt-bearer`
- `subject_token` (string, optional) — The JWT. Token exchange only.
- `subject_token_type` (enum, optional) — The type of `subject_token`. Token exchange only.
  - Allowed values: `urn:ietf:params:oauth:token-type:jwt`, `urn:ietf:params:oauth:token-type:id_token`
- `assertion` (string, optional) — The JWT. JWT bearer grant only.
- `requested_token_type` ("urn:ietf:params:oauth:token-type:access_token", optional) — Only the access token type.
- `audience` (string, optional) — The tenant host, when sent.
- `resource` (string, optional) — The tenant host, when sent.

## Response

### 200

The new token.

- `access_token` (string, required) — An opaque `crt_` token.
- `token_type` ("Bearer", required)
- `expires_in` (integer, required) — The life of the token, in seconds.
- `issued_token_type` (string, required) — The RFC 8693 issued token type.
- `scope` (string, required) — The scopes of the token, separated by spaces.

## Errors

### 400 Bad Request Error

A request or a token that the API refuses.

- `error` (enum, required) — The RFC 6749 error code.
  - Allowed values: `invalid_request`, `invalid_grant`, `unsupported_grant_type`, `invalid_target`
- `error_description` (string, required) — A text for the developer.

### 429 Too Many Requests Error

Too many token requests. Read `retry-after`.

- `error` (enum, required) — The RFC 6749 error code.
  - Allowed values: `invalid_request`, `invalid_grant`, `unsupported_grant_type`, `invalid_target`
- `error_description` (string, required) — A text for the developer.

### 500 Internal Server Error

An unexpected error.

- `error` (enum, required) — The RFC 6749 error code.
  - Allowed values: `invalid_request`, `invalid_grant`, `unsupported_grant_type`, `invalid_target`
- `error_description` (string, required) — A text for the developer.

### 503 Service Unavailable Error

The API cannot exchange the token now.

- `error` (enum, required) — The RFC 6749 error code.
  - Allowed values: `invalid_request`, `invalid_grant`, `unsupported_grant_type`, `invalid_target`
- `error_description` (string, required) — A text for the developer.

## Examples

**Request**

```json
{
  "grant_type": "urn:ietf:params:oauth:grant-type:token-exchange"
}
```

**Response**

```json
{
  "access_token": "string",
  "token_type": "string",
  "expires_in": 1,
  "issued_token_type": "string",
  "scope": "string"
}
```

**SDK Code**

```python
import requests

url = "https://your-org.cloudraker.run/v2/oauth/token"

payload = ""
headers = {"Content-Type": "application/x-www-form-urlencoded"}

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

print(response.json())
```

```javascript
const url = 'https://your-org.cloudraker.run/v2/oauth/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams('')
};

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

```go
package main

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

func main() {

	url := "https://your-org.cloudraker.run/v2/oauth/token"

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

	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

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

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

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

}
```

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

url = URI("https://your-org.cloudraker.run/v2/oauth/token")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'

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

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

HttpResponse<String> response = Unirest.post("https://your-org.cloudraker.run/v2/oauth/token")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://your-org.cloudraker.run/v2/oauth/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://your-org.cloudraker.run/v2/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/x-www-form-urlencoded"]

let request = NSMutableURLRequest(url: NSURL(string: "https://your-org.cloudraker.run/v2/oauth/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```