# Purchase number for location

POST https://services.leadconnectorhq.com/phone-system/numbers/location/{locationId}/purchase

Purchase number for location.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `phonenumbers.write`

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID as string |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "2023-02-21"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/phone-system/numbers/location/{locationId}/purchase": {
      "post": {
        "summary": "Purchase number for location",
        "operationId": "purchaseNumberForLocation",
        "description": "Purchase number for location.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "required": true,
            "description": "API Version",
            "schema": {
              "type": "string",
              "enum": [
                "2023-02-21"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location ID as string",
            "schema": {
              "type": "string",
              "example": "tDtDnQdgm2LXpyiqYvZ6"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PurchasePhoneNumberBodyDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": ""
          }
        },
        "security": [
          {
            "Location-Access": [
              "phonenumbers.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": {
      "PurchasePhoneNumberBodyDto": {
        "type": "object",
        "properties": {
          "phoneNumber": {
            "type": "string",
            "description": "phoneNumber to purchase",
            "example": "830236932"
          },
          "addressSid": {
            "type": "string",
            "description": "addressSid twilio address id",
            "example": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
          },
          "bundleSid": {
            "type": "string",
            "description": "bundleSid twilio bundle id",
            "example": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
          },
          "countryCode": {
            "type": "string",
            "description": "country for which the phone numbers are being requested",
            "example": "US"
          },
          "numberType": {
            "type": "object",
            "description": "type of phone number to be purchased",
            "example": "local"
          },
          "paymentIntentId": {
            "type": "string",
            "description": "stripe payment intent id",
            "example": "pi_3Oxxxxxxxxxxxxxxxxxxxx"
          },
          "stripeAccountId": {
            "type": "string",
            "description": "stripe account id",
            "example": "acct_1Oxxxxxxxxxxxxxxxx"
          },
          "paymentMethodId": {
            "type": "string",
            "description": "stripe registered payment method id",
            "example": "pm_1Oxxxxxxxxxxxxxxxx"
          },
          "locality": {
            "type": "string",
            "description": "locality of the user in which number is being purchased",
            "example": "Austin"
          },
          "region": {
            "type": "string",
            "description": "region of the user in which number is being purchased",
            "example": "TX"
          },
          "fingerprintId": {
            "type": "string",
            "description": "fingerprintId is request id which is unique for every purchase number request",
            "example": "purchase-req-abc-123"
          },
          "skipLocationKYC": {
            "type": "boolean",
            "description": "Skip location-level KYC verification if agency-level compliance has already been verified",
            "example": false
          }
        },
        "required": [
          "phoneNumber",
          "addressSid",
          "bundleSid",
          "countryCode",
          "numberType",
          "paymentIntentId",
          "stripeAccountId",
          "paymentMethodId",
          "locality",
          "region",
          "fingerprintId",
          "skipLocationKYC"
        ],
        "title": "PurchasePhoneNumberBodyDto"
      }
    }
  }
}
```

## HighLevel SDK Examples

**Node.js** (`@gohighlevel/api-client`)

```javascript
import HighLevel from '@gohighlevel/api-client';

const ghl = new HighLevel({
  privateIntegrationToken: '<PRIVATE_INTEGRATION_TOKEN>'
});

const body = {
  "phoneNumber": "830236932",
  "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "countryCode": "US",
  "numberType": "local",
  "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
  "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
  "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
  "locality": "Austin",
  "region": "TX",
  "fingerprintId": "purchase-req-abc-123",
  "skipLocationKYC": false
};

const response = await ghl.phoneSystem.purchaseNumberForLocation('<LOCATIONID>', body);
console.log(response);
```

**Python** (`gohighlevel-api-client`)

```python
from highlevel import HighLevel

client = HighLevel(
    private_integration_token='<PRIVATE_INTEGRATION_TOKEN>'
)

body = {
    "phoneNumber": "830236932",
    "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "countryCode": "US",
    "numberType": "local",
    "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
    "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
    "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
    "locality": "Austin",
    "region": "TX",
    "fingerprintId": "purchase-req-abc-123",
    "skipLocationKYC": false
}

response = await client.phoneSystem.purchase_number_for_location('<LOCATIONID>', body=body)
print(response)
```

**PHP** (`gohighlevel/api-client`)

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

use HighLevel\HighLevel;
use HighLevel\HighLevelConfig;

$config = new HighLevelConfig([
    'privateIntegrationToken' => '<PRIVATE_INTEGRATION_TOKEN>'
]);
$ghl = new HighLevel($config);

$body = [
    'phoneNumber' => '830236932',
    'addressSid' => 'ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'bundleSid' => 'BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'countryCode' => 'US',
    'numberType' => 'local',
    'paymentIntentId' => 'pi_3Oxxxxxxxxxxxxxxxxxxxx',
    'stripeAccountId' => 'acct_1Oxxxxxxxxxxxxxxxx',
    'paymentMethodId' => 'pm_1Oxxxxxxxxxxxxxxxx',
    'locality' => 'Austin',
    'region' => 'TX',
    'fingerprintId' => 'purchase-req-abc-123',
    'skipLocationKYC' => false
];

$response = $ghl->phoneSystem->purchaseNumberForLocation('<LOCATIONID>', $body);
echo json_encode($response, JSON_PRETTY_PRINT);
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/purchase' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: 2023-02-21' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "phoneNumber": "830236932",
  "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "countryCode": "US",
  "numberType": "local",
  "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
  "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
  "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
  "locality": "Austin",
  "region": "TX",
  "fingerprintId": "purchase-req-abc-123",
  "skipLocationKYC": false
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: '2023-02-21',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "phoneNumber": "830236932",
      "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "countryCode": "US",
      "numberType": "local",
      "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
      "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
      "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
      "locality": "Austin",
      "region": "TX",
      "fingerprintId": "purchase-req-abc-123",
      "skipLocationKYC": false
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/purchase', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/phone-system/numbers/location/{locationId}/purchase"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "2023-02-21"
}

payload = {
    "phoneNumber": "830236932",
    "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "countryCode": "US",
    "numberType": "local",
    "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
    "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
    "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
    "locality": "Austin",
    "region": "TX",
    "fingerprintId": "purchase-req-abc-123",
    "skipLocationKYC": false
}

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/phone-system/numbers/location/<locationId>/purchase',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: 2023-02-21',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "phoneNumber": "830236932",
  "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "countryCode": "US",
  "numberType": "local",
  "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
  "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
  "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
  "locality": "Austin",
  "region": "TX",
  "fingerprintId": "purchase-req-abc-123",
  "skipLocationKYC": false
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/purchase")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "2023-02-21")
  .header("Content-Type", "application/json")
  .body("{\"phoneNumber\":\"830236932\",\"addressSid\":\"ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"bundleSid\":\"BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"countryCode\":\"US\",\"numberType\":\"local\",\"paymentIntentId\":\"pi_3Oxxxxxxxxxxxxxxxxxxxx\",\"stripeAccountId\":\"acct_1Oxxxxxxxxxxxxxxxx\",\"paymentMethodId\":\"pm_1Oxxxxxxxxxxxxxxxx\",\"locality\":\"Austin\",\"region\":\"TX\",\"fingerprintId\":\"purchase-req-abc-123\",\"skipLocationKYC\":false}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/purchase"
  payload := strings.NewReader(`{
  "phoneNumber": "830236932",
  "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "countryCode": "US",
  "numberType": "local",
  "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
  "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
  "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
  "locality": "Austin",
  "region": "TX",
  "fingerprintId": "purchase-req-abc-123",
  "skipLocationKYC": false
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "2023-02-21")

  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/phone-system/numbers/location/<locationId>/purchase")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "2023-02-21"
request["Content-Type"] = "application/json"
request.body = '{
  "phoneNumber": "830236932",
  "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "countryCode": "US",
  "numberType": "local",
  "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
  "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
  "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
  "locality": "Austin",
  "region": "TX",
  "fingerprintId": "purchase-req-abc-123",
  "skipLocationKYC": false
}'

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

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "2023-02-21"
}

$body = '{
  "phoneNumber": "830236932",
  "addressSid": "ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "bundleSid": "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "countryCode": "US",
  "numberType": "local",
  "paymentIntentId": "pi_3Oxxxxxxxxxxxxxxxxxxxx",
  "stripeAccountId": "acct_1Oxxxxxxxxxxxxxxxx",
  "paymentMethodId": "pm_1Oxxxxxxxxxxxxxxxx",
  "locality": "Austin",
  "region": "TX",
  "fingerprintId": "purchase-req-abc-123",
  "skipLocationKYC": false
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/phone-system/numbers/location/<locationId>/purchase' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
