> This page is for Developer.

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

# Get OAuth Token

POST https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token
Content-Type: application/json

This endpoint allows you to generate a temporary OAuth token required to authenticate requests to the Powered by APIs. Franchises support a single OAuth token. Generating a new OAuth token will invalidate the previous OAuth token.

Reference: https://docs.bigcommerce.com/developer/docs/beta/powered-by/api-reference/auth/create-token

## Authentication

- `X-Auth-Client` header (required) — The client ID of the franchise API account.

## Request

### Headers

- `Accept` (string, required, default: application/json) — The [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of the response body.

### Body (application/json)

This endpoint expects an object.

- `duration` (double, required)

## Response

### 200

Success

- `access_token` (string, optional)
- `expires_at` (string, optional)

## Errors

### 401 Unauthorized Error

Unauthorized If a franchise makes a request with a client_id and client_secret that do not belong together, it returns a 401 Unauthorized response.

- `status` (double, optional)
- `title` (string, optional)
- `type` (string, optional)

### 403 Forbidden Error

Forbidden If a franchise makes a request with a valid `client_id` and `client_secret` that do not belong to the franchise or the franchise does not exist in the system, it returns a 403 Forbidden response.

- `status` (double, optional)
- `title` (string, optional)
- `type` (string, optional)

### 502 Bad Gateway Error

Bad Gateway If something happens during the request that causes it to fail, a 502 response is returned. A new request should be made.

- `status` (double, optional)
- `title` (string, optional)
- `type` (string, optional)

### 503 Service Unavailable Error

Service Unavailable If this occurs, you should retry the request. If you are unable to successfully make a request, please check the BigCommerce system status [here](http://status.bigcommerce.com/). A service is likely down and the request will need to be made again when it is back up.

- `status` (double, optional)
- `title` (string, optional)
- `type` (string, optional)

### 504 Gateway Timeout Error

Gateway Timeout If this occurs, you should retry the request. Typically retrying the request several times will result in a successful request. However, if you are unable to successfully make a request, please check the BigCommerce system status [here](http://status.bigcommerce.com/). A service is likely down and the request will need to be made again when it is back up.

- `status` (double, optional)
- `title` (string, optional)
- `type` (string, optional)
- `errors` (OauthTokenPostResponsesContentApplicationJsonSchemaErrors, optional)

## Types

### OauthTokenPostResponsesContentApplicationJsonSchemaErrors

## Examples

**Request**

```json
{
  "duration": 900
}
```

**Response**

```json
{
  "access_token": "string",
  "expires_at": "string"
}
```

**SDK Code**

```python Generate a token
import requests

url = "https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token"

payload = { "duration": 900 }
headers = {
    "Accept": "application/json",
    "X-Auth-Client": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Generate a token
const url = 'https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token';
const options = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'X-Auth-Client': '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"duration":900}'
};

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

```go Generate a token
package main

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

func main() {

	url := "https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token"

	payload := strings.NewReader("{\n  \"duration\": 900\n}")

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

	req.Header.Add("Accept", "application/json")
	req.Header.Add("X-Auth-Client", "<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 Generate a token
require 'uri'
require 'net/http'

url = URI("https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token")

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

request = Net::HTTP::Post.new(url)
request["Accept"] = 'application/json'
request["X-Auth-Client"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"duration\": 900\n}"

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

```java Generate a token
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token")
  .header("Accept", "application/json")
  .header("X-Auth-Client", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"duration\": 900\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token', [
  'body' => '{
  "duration": 900
}',
  'headers' => [
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
    'X-Auth-Client' => '<apiKey>',
  ],
]);

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

```csharp Generate a token
using RestSharp;

var client = new RestClient("https://api.bigcommerce.com/franchises/account_uuid/v1/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("X-Auth-Client", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"duration\": 900\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Generate a token
import Foundation

let headers = [
  "Accept": "application/json",
  "X-Auth-Client": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["duration": 900] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.bigcommerce.com/franchises/account_uuid/v1/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()
```