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

# Generate access token for protected actions using credentials

POST https://api-staging.nibtravelinsurance.com/users/{brandCode}/token
Content-Type: application/x-www-form-urlencoded

Reference: https://developer.nibtravelinsurance.com/reference/users-api/authentication/generate-access-token-for-protected-actions-using-credentials

## Request

### Path parameters

- `brandCode` (enum, required)
  - Allowed values: `nibau`, `nibnz`, `tidau`, `wn`

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

This endpoint expects an object.

- `grant_type` (string, required) — Use "password" to authenticate with credentials, and "refresh_token" to renew the access_token.
- `client_id` (string, required) — The Id of the type of client authenticating, e.g. "InternalApi", "ngPublicApp", "mobileApp", "ngUnderwriterApp". Required for both the "refresh_token" and "password" grant_types.
- `username` (string, optional) — The user's login. In most cases this is the user's email address. Required when using the "password" grant_type.
- `password` (string, optional) — The user's password. Required when using the "password" grant_type.
- `customerInterfaceId` (string, optional) — The client user interface type Id. Values to choose from are 1 (Public website), 2 (CSC website), 3 (Mobile app), 5 (Partner website) and 6 (Underwriter website). Required when using the "password" grant_type.
- `userTypeId` (string, optional) — The type id of the user trying to authenticate. Defaults to 1 (customer). Other values are 2 (Employee), 3 (Assistance Provider), 4 (Partner), 5 (Underwriter).
- `refresh_token` (string, optional) — The refresh token to use for renewal of the access token. Required when using the "refresh_token" grant_type.

## Response

### 200

Authentication result

- `access_token` (string, required)
- `token_type` (string, required)
- `expires_in` (integer, required) — Seconds until expiry.

## Errors

### 401 Post Brand Code Token Request Unauthorized Error

Authentication failure

- `error` (string, required)
- `error_description` (string, required)

## Examples

**Request**

```json
{
  "grant_type": "grant_type",
  "client_id": "client_id"
}
```

**Response**

```json
{
  "access_token": "access_token",
  "token_type": "token_type",
  "expires_in": 1
}
```

**SDK Code**

```python
import requests

url = "https://api-staging.nibtravelinsurance.com/users/nibau/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://api-staging.nibtravelinsurance.com/users/nibau/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://api-staging.nibtravelinsurance.com/users/nibau/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://api-staging.nibtravelinsurance.com/users/nibau/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://api-staging.nibtravelinsurance.com/users/nibau/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://api-staging.nibtravelinsurance.com/users/nibau/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api-staging.nibtravelinsurance.com/users/nibau/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://api-staging.nibtravelinsurance.com/users/nibau/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()
```