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

# OAuth Token

POST {{baseUrl}}/oauthv1/token
Content-Type: application/json

## OAuth Token Exchange

Exchange an authorization code for an access token using the OAuth 2.0 Authorization Code flow.

### Endpoint

`POST {{baseUrl}}/oauth/token`

### Request Headers

| Header       | Value            |
| ------------ | ---------------- |
| Content-Type | application/json |
| Accept       | application/json |

### Request Body

| Field          | Type   | Description                                                                         |
| -------------- | ------ | ----------------------------------------------------------------------------------- |
| `code`         | string | The authorization code received from the authorization server.                      |
| `clientId`     | string | The client ID of your application.                                                  |
| `clientSecret` | string | The client secret of your application.                                              |
| `redirectUri`  | string | The redirect URI used during the authorization request. Must match exactly.         |
| `grantType`    | string | Must be `authorization_code` for this flow.                                         |
| `refreshToken` | string | *(Optional)* A refresh token to obtain a new access token without re-authorization. |

### Example Request Body

```json
{
  "code": "auth-code-123456",
  "clientId": "client-id-123",
  "clientSecret": "client-secret-123",
  "redirectUri": "https://example.com/callback",
  "grantType": "authorization_code",
  "refreshToken": "refresh-token-123"
}
```

### Responses

#### ✅ 200 OK — Access token generated successfully

Returns an access token and related metadata.

#### ❌ 400 Bad Request — Invalid authorization code

Returned when the provided authorization code is invalid, expired, or already used.

***

Reference: https://docs.a1.uk.astutepayroll.in/api-reference/authentication/o-auth-token

## Request

### Body (application/json)

This endpoint expects an object.

- `code` (string, optional)
- `clientId` (string, optional)
- `redirectUri` (string, optional)
- `clientSecret` (string, optional)
- `grantType` (string, optional)
- `refreshToken` (string, optional)

## Examples

**Request**

```json
{
  "code": "{{code}}",
  "clientId": "{{clientId}}",
  "redirectUri": "{{redirectUri}}",
  "clientSecret": "{{clientSecret}}",
  "grantType": "{{authorization_code}}",
  "refreshToken": "{{refreshToken}}"
}
```

**SDK Code**

```python
import requests

url = "https://{{baseurl}}/oauthv1/token"

payload = {
    "code": "{{code}}",
    "clientId": "{{clientId}}",
    "redirectUri": "{{redirectUri}}",
    "clientSecret": "{{clientSecret}}",
    "grantType": "{{authorization_code}}",
    "refreshToken": "{{refreshToken}}"
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://{{baseurl}}/oauthv1/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"code":"{{code}}","clientId":"{{clientId}}","redirectUri":"{{redirectUri}}","clientSecret":"{{clientSecret}}","grantType":"{{authorization_code}}","refreshToken":"{{refreshToken}}"}'
};

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"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://{{baseurl}}/oauthv1/token"

	payload := strings.NewReader("{\n  \"code\": \"{{code}}\",\n  \"clientId\": \"{{clientId}}\",\n  \"redirectUri\": \"{{redirectUri}}\",\n  \"clientSecret\": \"{{clientSecret}}\",\n  \"grantType\": \"{{authorization_code}}\",\n  \"refreshToken\": \"{{refreshToken}}\"\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
require 'uri'
require 'net/http'

url = URI("https://{{baseurl}}/oauthv1/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  \"code\": \"{{code}}\",\n  \"clientId\": \"{{clientId}}\",\n  \"redirectUri\": \"{{redirectUri}}\",\n  \"clientSecret\": \"{{clientSecret}}\",\n  \"grantType\": \"{{authorization_code}}\",\n  \"refreshToken\": \"{{refreshToken}}\"\n}"

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://{{baseurl}}/oauthv1/token")
  .header("Content-Type", "application/json")
  .body("{\n  \"code\": \"{{code}}\",\n  \"clientId\": \"{{clientId}}\",\n  \"redirectUri\": \"{{redirectUri}}\",\n  \"clientSecret\": \"{{clientSecret}}\",\n  \"grantType\": \"{{authorization_code}}\",\n  \"refreshToken\": \"{{refreshToken}}\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://{{baseurl}}/oauthv1/token', [
  'body' => '{
  "code": "{{code}}",
  "clientId": "{{clientId}}",
  "redirectUri": "{{redirectUri}}",
  "clientSecret": "{{clientSecret}}",
  "grantType": "{{authorization_code}}",
  "refreshToken": "{{refreshToken}}"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://{{baseurl}}/oauthv1/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"code\": \"{{code}}\",\n  \"clientId\": \"{{clientId}}\",\n  \"redirectUri\": \"{{redirectUri}}\",\n  \"clientSecret\": \"{{clientSecret}}\",\n  \"grantType\": \"{{authorization_code}}\",\n  \"refreshToken\": \"{{refreshToken}}\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "code": "{{code}}",
  "clientId": "{{clientId}}",
  "redirectUri": "{{redirectUri}}",
  "clientSecret": "{{clientSecret}}",
  "grantType": "{{authorization_code}}",
  "refreshToken": "{{refreshToken}}"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://{{baseurl}}/oauthv1/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()
```