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

# Generate OAuth 2.0 token

POST https://expenses-api.bcdtravel.com/oauth2/token

Generate an access token using OAuth 2.0 client credentials.

Reference: https://bcdtravel.ferndocs.com/invoice/api-reference/travel-expenses-api-invoice/auth/generate-token

## Authentication

- `Authorization` header (basic auth, required) — Basic authentication of the form `Basic <base64(username:password)>`.

## Servers

- `https://expenses-api.bcdtravel.com` (https://expenses-api.bcdtravel.com, default)
- `https://auth.bcdtravel.com` (https://auth.bcdtravel.com)

## Response

### 200

Generate OAuth 2.0 Token

- `access_token` (string, optional)
- `expires_in` (integer, optional)
- `token_type` (string, optional)

## Examples

**Response**

```json
{
  "access_token": "Token",
  "expires_in": 3600,
  "token_type": "Bearer"
}
```

**SDK Code**

```python Auth_generateToken_example
import requests

url = "https://expenses-api.bcdtravel.com/oauth2/token"

response = requests.post(url, auth=("<username>", "<password>"))

print(response.json())
```

```javascript Auth_generateToken_example
const url = 'https://expenses-api.bcdtravel.com/oauth2/token';
const credentials = btoa("<username>:<password>");

const options = {method: 'POST', headers: {Authorization: `Basic ${credentials}`}};

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

```go Auth_generateToken_example
package main

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

func main() {

	url := "https://expenses-api.bcdtravel.com/oauth2/token"

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

	req.SetBasicAuth("<username>", "<password>")

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

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

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

}
```

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

url = URI("https://expenses-api.bcdtravel.com/oauth2/token")

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

request = Net::HTTP::Post.new(url)
request.basic_auth("<username>", "<password>")

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

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

HttpResponse<String> response = Unirest.post("https://expenses-api.bcdtravel.com/oauth2/token")
  .basicAuth("<username>", "<password>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://expenses-api.bcdtravel.com/oauth2/token', [
  'headers' => [
  ],
    'auth' => ['<username>', '<password>'],
]);

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

```csharp Auth_generateToken_example
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://expenses-api.bcdtravel.com/oauth2/token");
client.Authenticator = new HttpBasicAuthenticator("<username>", "<password>");
var request = new RestRequest(Method.POST);

IRestResponse response = client.Execute(request);
```

```swift Auth_generateToken_example
import Foundation

let credentials = Data("<username>:<password>".utf8).base64EncodedString()

let headers = ["Authorization": "Basic \(credentials)"]

let request = NSMutableURLRequest(url: NSURL(string: "https://expenses-api.bcdtravel.com/oauth2/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()
```