> ## Documentation Index
> Fetch the complete documentation index at: https://developers.leadwaycrm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Purchase a phone number

> Purchase a phone number for a specific account.

Purchase a phone number for a specific account.

```http theme={null}
POST https://services.leadconnectorhq.com/phone-system/numbers/location/{locationId}/purchase
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Path parameters

<ParamField path="locationId" type="string" required default="ve9EPM428h8vShlRW1KT">
  The unique identifier of the account
</ParamField>

## Body

<ParamField body="phoneNumber" type="string" required default="+18305551234">
  The phone number to purchase
</ParamField>

<ParamField body="countryCode" type="string" default="US">
  ISO 3166-1 alpha-2 country code of the number
</ParamField>

<ParamField body="numberType" type="string" default="local">
  Type of phone number Posibles valores: 'local', 'tollFree', 'mobile'
</ParamField>

<ParamField body="addressSid" type="string" default="AD1234567890abcdef1234567890abcde">
  Twilio address SID for compliance
</ParamField>

<ParamField body="bundleSid" type="string" default="BU1234567890abcdef1234567890abcde">
  Twilio bundle SID for regulatory compliance
</ParamField>

<ParamField body="locality" type="string" default="San Antonio">
  Locality where the number is being purchased
</ParamField>

<ParamField body="region" type="string" default="TX">
  Region where the number is being purchased
</ParamField>

<ParamField body="fingerprintId" type="string" default="fp_abc123def456">
  Unique request ID for idempotency (fingerprint of the purchase request)
</ParamField>

<ParamField body="skipLocationKYC" type="boolean" default="False">
  Skip account-level KYC verification if agency-level compliance has already been verified
</ParamField>

## Respuestas

<Accordion title="201 - Phone number successfully purchased. Returns the updated Twilio account state for the account.">
  <ResponseField name="id" type="string" required default="8xMPW85D2z5jgcTa5L1p">
    Unique identifier of the Twilio account record
  </ResponseField>

  <ResponseField name="account_sid" type="string" required default="ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
    Twilio Account SID
  </ResponseField>

  <ResponseField name="under_ghl_account" type="boolean" required default="True">
    Whether this account is under a GHL-managed Twilio account
  </ResponseField>

  <ResponseField name="validate_sms" type="boolean" required default="True">
    Whether SMS validation is enabled
  </ResponseField>

  <ResponseField name="location_id" type="string" required default="aa4PBpxnPc9bs4LSdiW7">
    The account ID this Twilio account belongs to
  </ResponseField>

  <ResponseField name="migration_status" type="string" default="completed">
    Current migration status of the account
  </ResponseField>

  <ResponseField name="migration_numbers" type="string[]">
    List of numbers being migrated
  </ResponseField>

  <ResponseField name="assigned_to_numbers" type="object">
    Map of phone numbers to assigned user IDs
  </ResponseField>

  <ResponseField name="numbers" type="object" required>
    Map of phone numbers to their service type (e.g. 'conversation')
  </ResponseField>

  <ResponseField name="number_name" type="object">
    Map of phone numbers to their friendly names
  </ResponseField>

  <ResponseField name="new_account_sid" type="string" default="">
    New account SID if the account has been migrated to new credentials
  </ResponseField>

  ```json theme={null}
  {
    "id": "8xMPW85D2z5jgcTa5L1p",
    "account_sid": "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "under_ghl_account": true,
    "validate_sms": true,
    "location_id": "aa4PBpxnPc9bs4LSdiW7",
    "migration_numbers": [],
    "assigned_to_numbers": {},
    "numbers": {
      "+18705871861": "conversation"
    },
    "number_name": {
      "+18705871861": "My Number"
    },
    "new_account_sid": ""
  }
  ```
</Accordion>

<Accordion title="400 - Bad request - Invalid parameters or number unavailable">
  <ResponseField name="message" type="string" default="Phone number is no longer available" />

  <ResponseField name="error" type="string" default="Bad Request" />

  <ResponseField name="statusCode" type="number" default="400" />

  ```json theme={null}
  {
    "message": "Phone number is no longer available",
    "error": "Bad Request",
    "statusCode": 400
  }
  ```
</Accordion>

<Accordion title="401 - Unauthorized">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="500 - Internal server error - An unexpected error occurred while purchasing the phone number" />

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/phone-system/numbers/location/YOUR_locationId/purchase' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "phoneNumber": "+18305551234",
    "countryCode": "US",
    "numberType": "local",
    "addressSid": "AD1234567890abcdef1234567890abcde",
    "bundleSid": "BU1234567890abcdef1234567890abcde",
    "locality": "San Antonio",
    "region": "TX",
    "fingerprintId": "fp_abc123def456",
    "skipLocationKYC": false
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/phone-system/numbers/location/YOUR_locationId/purchase', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"phoneNumber": "+18305551234", "countryCode": "US", "numberType": "local", "addressSid": "AD1234567890abcdef1234567890abcde", "bundleSid": "BU1234567890abcdef1234567890abcde", "locality": "San Antonio", "region": "TX", "fingerprintId": "fp_abc123def456", "skipLocationKYC": false}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/phone-system/numbers/location/YOUR_locationId/purchase',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"phoneNumber": "+18305551234", "countryCode": "US", "numberType": "local", "addressSid": "AD1234567890abcdef1234567890abcde", "bundleSid": "BU1234567890abcdef1234567890abcde", "locality": "San Antonio", "region": "TX", "fingerprintId": "fp_abc123def456", "skipLocationKYC": false},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/phone-system/numbers/location/YOUR_locationId/purchase');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'phoneNumber': '+18305551234', 'countryCode': 'US', 'numberType': 'local', 'addressSid': 'AD1234567890abcdef1234567890abcde', 'bundleSid': 'BU1234567890abcdef1234567890abcde', 'locality': 'San Antonio', 'region': 'TX', 'fingerprintId': 'fp_abc123def456', 'skipLocationKYC': false}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
