# Get Location Access Token from Agency Token

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

This API allows you to generate locationAccessToken from AgencyAccessToken

## Authentication

Send `Authorization: Bearer <token>` using:

- **Agency token: OAuth access token only (Private Integration Tokens are not accepted).** Scopes: `oauth.write`

## 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/location-token": {
      "post": {
        "summary": "Get Location Access Token from Agency Token",
        "operationId": "getLocationAccessTokenFromAgencyToken",
        "description": "This API allows you to generate locationAccessToken from AgencyAccessToken",
        "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/GetLocationAccessCodeBodyDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetLocationAccessTokenV3SuccessfulResponseDto"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Agency-Access-Only": [
              "oauth.write"
            ]
          }
        ]
      }
    }
  },
  "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": {
      "GetLocationAccessCodeBodyDto": {
        "type": "object",
        "properties": {
          "companyId": {
            "type": "string",
            "description": "Company Id of location you want to request token for",
            "example": "tDtDnQdgm2LXpyiqYvZ6"
          },
          "locationId": {
            "type": "string",
            "description": "The location ID for which you want to obtain accessToken",
            "example": "l1C08ntBrFjLS0elLIYU"
          }
        },
        "required": [
          "companyId",
          "locationId"
        ],
        "title": "GetLocationAccessCodeBodyDto"
      },
      "GetLocationAccessTokenV3SuccessfulResponseDto": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string",
            "example": "ab12dc0ae1234a7898f9ff06d4f69gh",
            "description": "Location access token which can be used to authenticate & authorize API under following scope"
          },
          "token_type": {
            "type": "string",
            "example": "Bearer",
            "description": "The token type (always Bearer)"
          },
          "expires_in": {
            "type": "number",
            "example": 86399,
            "description": "Time in seconds remaining for token to expire"
          },
          "scope": {
            "type": "string",
            "example": "conversations/message.readonly conversations/message.write",
            "description": "Scopes the following accessToken have access to"
          },
          "locationId": {
            "type": "string",
            "description": "Location ID - Present only for Sub-Account Access Token",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "planId": {
            "type": "string",
            "description": "Plan Id of the subscribed plan in paid apps.",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "userId": {
            "type": "string",
            "description": "USER ID - Represent user id of person who performed installation",
            "example": "l1C08ntBrFjLS0elLIYU"
          },
          "appId": {
            "type": "string",
            "description": "App ID of the installed application",
            "example": "6578278e879ad2646715ba9c"
          },
          "versionId": {
            "type": "string",
            "description": "Version ID of the installed app version",
            "example": "6578278e879ad2646715ba9c"
          },
          "refresh_token": {
            "type": "string",
            "description": "The OAuth2 refresh token used to obtain a new access token for this specific location.",
            "example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"
          }
        },
        "required": [
          "userId"
        ],
        "title": "GetLocationAccessTokenV3SuccessfulResponseDto"
      },
      "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/location-token' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-raw '{
  "companyId": "tDtDnQdgm2LXpyiqYvZ6",
  "locationId": "l1C08ntBrFjLS0elLIYU"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: JSON.stringify({
      "companyId": "tDtDnQdgm2LXpyiqYvZ6",
      "locationId": "l1C08ntBrFjLS0elLIYU"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/oauth/location-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/location-token"

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

payload = {
    "companyId": "tDtDnQdgm2LXpyiqYvZ6",
    "locationId": "l1C08ntBrFjLS0elLIYU"
}

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/location-token',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/x-www-form-urlencoded',
  ],
  CURLOPT_POSTFIELDS => '{
  "companyId": "tDtDnQdgm2LXpyiqYvZ6",
  "locationId": "l1C08ntBrFjLS0elLIYU"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/oauth/location-token")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .body("{\"companyId\":\"tDtDnQdgm2LXpyiqYvZ6\",\"locationId\":\"l1C08ntBrFjLS0elLIYU\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/oauth/location-token"
  payload := strings.NewReader(`{
  "companyId": "tDtDnQdgm2LXpyiqYvZ6",
  "locationId": "l1C08ntBrFjLS0elLIYU"
}`)
  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/location-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 = '{
  "companyId": "tDtDnQdgm2LXpyiqYvZ6",
  "locationId": "l1C08ntBrFjLS0elLIYU"
}'

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

**PowerShell**

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

$body = '{
  "companyId": "tDtDnQdgm2LXpyiqYvZ6",
  "locationId": "l1C08ntBrFjLS0elLIYU"
}'

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