# Get Access Token

POST https://services.leadconnectorhq.com/oauth/token

Use Access Tokens to access CRM resources on behalf of an authenticated location/company.

## Authentication

None: this endpoint declares no security requirement, so no `Authorization` header is needed.

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/oauth/token": {
      "post": {
        "summary": "Get Access Token",
        "operationId": "getAccessToken",
        "description": "Use Access Tokens to access CRM resources on behalf of an authenticated location/company.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/GetAccessTokenBodyDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetAccessTokenSuccessfulResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                },
                "examples": {
                  "invalidParameter": {
                    "summary": "Thrown when any parameter (grant_type, client_id, client_secret, refresh_token, etc.) has an invalid value.",
                    "value": {
                      "statusCode": 400,
                      "message": "Invalid parameter: grant_type"
                    }
                  },
                  "missingParameter": {
                    "summary": "Thrown when a required parameter (grant_type, client_id, client_secret, refresh_token, etc.) is missing from the request.",
                    "value": {
                      "statusCode": 400,
                      "message": "Missing parameter: client_id"
                    }
                  },
                  "invalidRefreshToken": {
                    "summary": "Thrown when the supplied refresh token is invalid, expired, or has already been used.",
                    "value": {
                      "statusCode": 400,
                      "message": "Invalid grant: refresh token is invalid"
                    }
                  },
                  "locationNotActive": {
                    "summary": "Thrown when the location is not active (Due to SaaS subscription incomplete, paused, canceled, etc. Agency manually paused location. Agency becomes inactive.). Once the location becomes active again, the same refresh token can be used to get a new access token, provided the app is still installed on the location.",
                    "value": {
                      "statusCode": 400,
                      "message": "Location is not active"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "GetAccessTokenBodyDto": {
        "type": "object",
        "properties": {
          "client_id": {
            "type": "string",
            "description": "The ID provided by CRM for your integration",
            "example": "6578278e879ad2646715ba9c"
          },
          "client_secret": {
            "type": "string",
            "description": "The client secret provided by CRM for your integration",
            "example": "ab12dc0ae1234a7898f9ff06d4f69gh"
          },
          "grant_type": {
            "type": "string",
            "description": "The OAuth2 grant type — authorization_code, refresh_token, or client_credentials",
            "enum": [
              "authorization_code",
              "refresh_token",
              "client_credentials"
            ],
            "example": "authorization_code"
          },
          "code": {
            "type": "string",
            "description": "The authorization code received from the authorization endpoint (required for authorization_code grant)",
            "example": "ab12dc0ae1234a7898f9ff06d4f69gh"
          },
          "refresh_token": {
            "type": "string",
            "description": "The refresh token used to obtain a new access token (required for refresh_token grant)",
            "example": "xy34dc0ae1234a4858f9ff06d4f66ba"
          },
          "user_type": {
            "type": "string",
            "description": "The type of token to be requested",
            "example": "Location",
            "enum": [
              "Company",
              "Location"
            ]
          },
          "redirect_uri": {
            "type": "string",
            "description": "The redirect URI for your application",
            "example": "https://myapp.com/oauth/callback/crm"
          }
        },
        "required": [
          "client_id",
          "client_secret",
          "grant_type"
        ],
        "title": "GetAccessTokenBodyDto"
      },
      "GetAccessTokenSuccessfulResponseDto": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string",
            "example": "ab12dc0ae1234a7898f9ff06d4f69gh",
            "description": "The OAuth2 access token"
          },
          "token_type": {
            "type": "string",
            "example": "Bearer",
            "description": "The token type (always Bearer)"
          },
          "expires_in": {
            "type": "number",
            "example": 86399,
            "description": "Time in seconds until the access token expires"
          },
          "refresh_token": {
            "type": "string",
            "example": "xy34dc0ae1234a4858f9ff06d4f66ba",
            "description": "The OAuth2 refresh token used to obtain a new access token"
          },
          "scope": {
            "type": "string",
            "example": "conversations/message.readonly conversations/message.write",
            "description": "Space-separated list of scopes the access token has access to"
          },
          "userType": {
            "type": "string",
            "example": "Location",
            "description": "The user type associated with the token (Location or Company)"
          },
          "locationId": {
            "type": "string",
            "description": "Location ID - Present only for Sub-Account Access Token",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "companyId": {
            "type": "string",
            "description": "Company ID",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "approvedLocations": {
            "description": "Approved locations to generate location access token",
            "example": [
              "l1C08ntBrFjLS0elLIYU"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "userId": {
            "type": "string",
            "description": "USER ID - Represent user id of person who performed installation",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "planId": {
            "type": "string",
            "description": "Plan Id of the subscribed plan in paid apps.",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "isBulkInstallation": {
            "type": "boolean",
            "description": "Indicates whether the installation was performed as a bulk installation",
            "example": false
          },
          "installToFutureLocations": {
            "type": "boolean",
            "description": "Boolean to control if user wants app to be automatically installed to future locations (only for company tokens)",
            "example": true
          },
          "approveAllLocations": {
            "type": "boolean",
            "description": "Boolean indicating if user approved all locations during bulk installation (only for company tokens)",
            "example": true
          }
        },
        "required": [
          "userId"
        ],
        "title": "GetAccessTokenSuccessfulResponseDto"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/oauth/token' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-raw '{
  "client_id": "6578278e879ad2646715ba9c",
  "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "grant_type": "authorization_code",
  "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
  "user_type": "Location",
  "redirect_uri": "https://myapp.com/oauth/callback/crm"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: JSON.stringify({
      "client_id": "6578278e879ad2646715ba9c",
      "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
      "grant_type": "authorization_code",
      "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
      "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
      "user_type": "Location",
      "redirect_uri": "https://myapp.com/oauth/callback/crm"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/oauth/token', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/oauth/token"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "client_id": "6578278e879ad2646715ba9c",
    "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
    "grant_type": "authorization_code",
    "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
    "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
    "user_type": "Location",
    "redirect_uri": "https://myapp.com/oauth/callback/crm"
}

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

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/oauth/token',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/x-www-form-urlencoded',
  ],
  CURLOPT_POSTFIELDS => '{
  "client_id": "6578278e879ad2646715ba9c",
  "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "grant_type": "authorization_code",
  "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
  "user_type": "Location",
  "redirect_uri": "https://myapp.com/oauth/callback/crm"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/oauth/token")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .body("{\"client_id\":\"6578278e879ad2646715ba9c\",\"client_secret\":\"ab12dc0ae1234a7898f9ff06d4f69gh\",\"grant_type\":\"authorization_code\",\"code\":\"ab12dc0ae1234a7898f9ff06d4f69gh\",\"refresh_token\":\"xy34dc0ae1234a4858f9ff06d4f66ba\",\"user_type\":\"Location\",\"redirect_uri\":\"https://myapp.com/oauth/callback/crm\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/oauth/token"
  payload := strings.NewReader(`{
  "client_id": "6578278e879ad2646715ba9c",
  "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "grant_type": "authorization_code",
  "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
  "user_type": "Location",
  "redirect_uri": "https://myapp.com/oauth/callback/crm"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

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

url = URI("https://services.leadconnectorhq.com/oauth/token")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "client_id": "6578278e879ad2646715ba9c",
  "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "grant_type": "authorization_code",
  "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
  "user_type": "Location",
  "redirect_uri": "https://myapp.com/oauth/callback/crm"
}'

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

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "client_id": "6578278e879ad2646715ba9c",
  "client_secret": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "grant_type": "authorization_code",
  "code": "ab12dc0ae1234a7898f9ff06d4f69gh",
  "refresh_token": "xy34dc0ae1234a4858f9ff06d4f66ba",
  "user_type": "Location",
  "redirect_uri": "https://myapp.com/oauth/callback/crm"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/oauth/token' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/x-www-form-urlencoded'
$response | ConvertTo-Json
```
