> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# purchase

> Purchase a new phone number.

Purchase a new phone number for the account.

### Schema

```yaml
openapi: 3.1.0
info:
  title: API
  version: 1.0.0
paths:
  /Accounts/{AccountSid}/IncomingPhoneNumbers:
    post:
      operationId: create_incoming_phone_number
      summary: Create an Incoming Phone Number
      description: >-
        Purchase and provision a new incoming phone number.


        #### Permissions


        The API token used to authenticate must have the following scope(s)
        enabled to make a successful request: _Numbers_.


        [Learn more about API scopes](/docs/platform/your-signalwire-api-space).
      tags:
        - subpackage_incomingPhoneNumbers
      parameters:
        - name: AccountSid
          in: path
          description: >-
            The unique identifier for the account that is associated with this
            phone number.
          required: true
          schema:
            $ref: '#/components/schemas/uuid'
      responses:
        '201':
          description: Response returned when an incoming phone number is created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IncomingPhoneNumber'
        '400':
          description: >-
            The request was invalid or cannot be processed. Check the error
            details for more information.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompatibilityErrorResponse'
        '401':
          description: Authentication failed. Please verify your credentials and try again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompatibilityErrorResponse'
        '422':
          description: >-
            The request could not be processed due to validation errors. Check
            the error details for more information.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CompatibilityErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateIncomingPhoneNumberRequest'
servers:
  - url: https://YOUR_SPACE.signalwire.com/api/laml/2010-04-01
    description: SignalWire Compatibility API
components:
  schemas:
    uuid:
      type: string
      format: uuid
      description: Universal Unique Identifier.
      title: uuid
    CreateIncomingPhoneNumberRequestSmsFallbackMethod:
      type: string
      enum:
        - GET
        - POST
      default: POST
      description: >-
        Whether the request to `SmsFallbackUrl` is a `GET` or a `POST`. Default
        is `POST`.
      title: CreateIncomingPhoneNumberRequestSmsFallbackMethod
    CreateIncomingPhoneNumberRequestSmsMethod:
      type: string
      enum:
        - GET
        - POST
      default: POST
      description: Whether the request to SmsUrl is a `GET` or a `POST`. Default is `POST`.
      title: CreateIncomingPhoneNumberRequestSmsMethod
    CreateIncomingPhoneNumberRequestStatusCallbackMethod:
      type: string
      enum:
        - GET
        - POST
      default: POST
      description: >-
        Whether the request to StatusCallback is a `GET` or a `POST`. Default is
        `POST`.
      title: CreateIncomingPhoneNumberRequestStatusCallbackMethod
    CreateIncomingPhoneNumberRequestVoiceFallbackMethod:
      type: string
      enum:
        - GET
        - POST
      default: POST
      description: >-
        Whether the request to VoiceFallbackUrl is a `GET` or a `POST`. Default
        is `POST`.
      title: CreateIncomingPhoneNumberRequestVoiceFallbackMethod
    CreateIncomingPhoneNumberRequestVoiceMethod:
      type: string
      enum:
        - GET
        - POST
      default: POST
      description: >-
        Whether the request to VoiceUrl is a `GET` or a `POST`. Default is
        `POST`.
      title: CreateIncomingPhoneNumberRequestVoiceMethod
    CreateIncomingPhoneNumberRequestVoiceReceiveMode:
      type: string
      enum:
        - voice
        - fax
      default: voice
      description: >-
        Whether this number can receive voice calls or faxes. Default is
        `voice`.
      title: CreateIncomingPhoneNumberRequestVoiceReceiveMode
    CreateIncomingPhoneNumberRequest:
      type: object
      properties:
        PhoneNumber:
          type: string
          description: >-
            The phone number to purchase in E.164 format. Must start with `+`
            followed by 5-17 digits.
        FriendlyName:
          type: string
          description: >-
            A friendly name for the phone number. If not provided, the formatted
            phone number will be used.
        SmsApplicationSid:
          $ref: '#/components/schemas/uuid'
          description: >-
            The unique identifier for the application associated with SMS
            handling on this phone number.
        SmsFallbackMethod:
          $ref: >-
            #/components/schemas/CreateIncomingPhoneNumberRequestSmsFallbackMethod
          default: POST
          description: >-
            Whether the request to `SmsFallbackUrl` is a `GET` or a `POST`.
            Default is `POST`.
        SmsFallbackUrl:
          type: string
          format: uri
          description: The URL to request if errors occur when fetching SmsUrl.
        SmsMethod:
          $ref: '#/components/schemas/CreateIncomingPhoneNumberRequestSmsMethod'
          default: POST
          description: >-
            Whether the request to SmsUrl is a `GET` or a `POST`. Default is
            `POST`.
        SmsUrl:
          type: string
          format: uri
          description: The URL to request when an incoming SMS is received.
        StatusCallback:
          type: string
          format: uri
          description: >-
            The URL to request to pass status updates to. See the [Incoming call
            status
            callback](/docs/compatibility-api/rest/incoming-phone-numbers/webhooks/incoming-call-status-callback)
            webhook for the payload your URL will receive.
        StatusCallbackMethod:
          $ref: >-
            #/components/schemas/CreateIncomingPhoneNumberRequestStatusCallbackMethod
          default: POST
          description: >-
            Whether the request to StatusCallback is a `GET` or a `POST`.
            Default is `POST`.
        VoiceApplicationSid:
          $ref: '#/components/schemas/uuid'
          description: >-
            The unique identifier for the application associated with call
            handling on this phone number.
        VoiceFallbackMethod:
          $ref: >-
            #/components/schemas/CreateIncomingPhoneNumberRequestVoiceFallbackMethod
          default: POST
          description: >-
            Whether the request to VoiceFallbackUrl is a `GET` or a `POST`.
            Default is `POST`.
        VoiceFallbackUrl:
          type: string
          format: uri
          description: The URL to request if errors occur when fetching VoiceUrl.
        VoiceMethod:
          $ref: '#/components/schemas/CreateIncomingPhoneNumberRequestVoiceMethod'
          default: POST
          description: >-
            Whether the request to VoiceUrl is a `GET` or a `POST`. Default is
            `POST`.
        VoiceReceiveMode:
          $ref: >-
            #/components/schemas/CreateIncomingPhoneNumberRequestVoiceReceiveMode
          default: voice
          description: >-
            Whether this number can receive voice calls or faxes. Default is
            `voice`.
        VoiceUrl:
          type: string
          format: uri
          description: The URL to request when an incoming call is received.
      required:
        - PhoneNumber
      description: Request body for creating an incoming phone number.
      title: CreateIncomingPhoneNumberRequest
    AddressRequirements:
      type: string
      enum:
        - none
        - any
        - local
        - foreign
      description: Address requirements.
      title: AddressRequirements
    IncomingPhoneNumberCapabilities:
      type: object
      properties:
        voice:
          type: boolean
          description: Whether or not voice is enabled.
        sms:
          type: boolean
          description: Whether or not SMS is enabled.
        mms:
          type: boolean
          description: Whether or not MMS is enabled.
        fax:
          type: boolean
          description: Whether or not fax is enabled.
      required:
        - voice
        - sms
        - mms
        - fax
      description: Phone number capabilities.
      title: IncomingPhoneNumberCapabilities
    PhoneNumberOrigin:
      type: string
      enum:
        - signalwire
        - hosted
      description: Phone number origin.
      title: PhoneNumberOrigin
    IncomingPhoneNumber:
      type: object
      properties:
        account_id:
          $ref: '#/components/schemas/uuid'
          description: >-
            The unique identifier for the account that is associated with this
            phone number.
        account_sid:
          $ref: '#/components/schemas/uuid'
          description: >-
            The unique identifier for the account that is associated with this
            phone number.
        address_requirements:
          $ref: '#/components/schemas/AddressRequirements'
          description: >-
            Whether or not a registered address with SignalWire is required.
            Always 'none'.
        address_sid:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier for the address associated with this phone
            number. Always null.
        api_version:
          type: string
          description: The version of the SignalWire API.
        beta:
          type: boolean
          description: New numbers on SignalWire are marked as beta. Always false.
        capabilities:
          $ref: '#/components/schemas/IncomingPhoneNumberCapabilities'
          description: Whether or not a number can receive calls and messages.
        country_code:
          type: string
          description: The ISO 3166-1 alpha-2 country code for this phone number.
        date_created:
          type: string
          description: The date, in RFC 2822 format, this phone number was created.
        date_updated:
          type: string
          description: The date, in RFC 2822 format, this phone number was updated.
        emergency_address_sid:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier of the address associated with E911 for this
            phone number, or null if not set.
        emergency_status:
          type: string
          description: >-
            Whether the phone route has an active E911 address associated.
            'Active' or 'Inactive'.
        friendly_name:
          type: string
          description: A formatted version of the number.
        identity_sid:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier for the identity associated with this phone
            number. Always null.
        origin:
          $ref: '#/components/schemas/PhoneNumberOrigin'
          description: The origin of the phone number.
        phone_number:
          type: string
          description: The incoming number in E.164 format.
        sid:
          type: string
          description: The unique identifier for this phone number.
        sms_application_sid:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier for the application associated with SMS
            handling on this phone number, or null if not set.
        sms_fallback_method:
          type: string
          description: Whether the request to `SmsFallbackUrl` is a `GET` or a `POST`.
        sms_fallback_url:
          type:
            - string
            - 'null'
          description: >-
            The URL to request if errors occur when fetching SmsUrl, or null if
            not set.
        sms_method:
          type: string
          description: Whether the request to SmsUrl is a `GET` or a `POST`.
        sms_url:
          type:
            - string
            - 'null'
          description: >-
            The URL to request when an incoming SMS is received, or null if not
            set.
        status_callback:
          type:
            - string
            - 'null'
          description: The URL to request to pass status updates to, or null if not set.
        status_callback_method:
          type: string
          description: Whether the request to StatusCallback is a `GET` or a `POST`.
        trunk_sid:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier for the Trunk associated with this phone
            number. Always null.
        uri:
          type: string
          description: The URI for this number.
        verification_status:
          type: string
          description: >-
            The verification status for toll-free numbers. Only present for
            toll-free numbers.
        voice_application_sid:
          type:
            - string
            - 'null'
          description: >-
            The unique identifier for the application associated with call
            handling on this phone number, or null if not set.
        voice_caller_id_lookup:
          type:
            - boolean
            - 'null'
          description: >-
            Whether or not to look up a caller's name in the database. Always
            null.
        voice_fallback_method:
          type: string
          description: Whether the request to VoiceFallbackUrl is a `GET` or a `POST`.
        voice_fallback_url:
          type:
            - string
            - 'null'
          description: >-
            The URL to request if errors occur when fetching `Url`, or null if
            not set.
        voice_method:
          type: string
          description: Whether the request to Url is a `GET` or a `POST`.
        voice_url:
          type:
            - string
            - 'null'
          description: >-
            The URL to request when an incoming call is received, or null if not
            set.
      required:
        - account_id
        - account_sid
        - address_requirements
        - address_sid
        - api_version
        - beta
        - capabilities
        - country_code
        - date_created
        - date_updated
        - emergency_address_sid
        - emergency_status
        - friendly_name
        - identity_sid
        - origin
        - phone_number
        - sid
        - sms_application_sid
        - sms_fallback_method
        - sms_fallback_url
        - sms_method
        - sms_url
        - status_callback
        - status_callback_method
        - trunk_sid
        - uri
        - voice_application_sid
        - voice_caller_id_lookup
        - voice_fallback_method
        - voice_fallback_url
        - voice_method
        - voice_url
      description: Incoming phone number model.
      title: IncomingPhoneNumber
    CompatibilityErrorResponse:
      type: object
      properties:
        code:
          type: integer
          description: Error code.
        message:
          type: string
          description: Error message.
        more_info:
          type: string
          description: URL for more information about the error.
        status:
          type: integer
          description: HTTP status code.
      required:
        - code
        - message
        - more_info
        - status
      description: Error response model.
      title: CompatibilityErrorResponse

```

## **Response Example**

### Response (201)

```json
{
  "account_id": "b3877c40-da60-4998-90ad-b792e98472ac",
  "account_sid": "b3877c40-da60-4998-90ad-b792e98472ac",
  "address_requirements": "none",
  "address_sid": null,
  "api_version": "2010-04-01",
  "beta": false,
  "capabilities": {
    "voice": true,
    "sms": true,
    "mms": true,
    "fax": true
  },
  "country_code": "US",
  "date_created": "Tue, 25 Sept 2018 23:00:00 +0000",
  "date_updated": "Wed, 26 Sept 2018 22:00:00 +0000",
  "emergency_address_sid": null,
  "emergency_status": "Inactive",
  "friendly_name": "(310) 338-6745",
  "identity_sid": null,
  "origin": "signalwire",
  "phone_number": "+13103386745",
  "sid": "b3877c40-da60-4998-90ad-b792e98472pn",
  "sms_application_sid": null,
  "sms_fallback_method": "POST",
  "sms_fallback_url": null,
  "sms_method": "POST",
  "sms_url": null,
  "status_callback": null,
  "status_callback_method": "POST",
  "trunk_sid": null,
  "uri": "/api/laml/2010-04-01/Accounts/b3877c40-da60-4998-90ad-b792e98472ac/IncomingPhoneNumbers/b3877c40-da60-4998-90ad-b792e98472pn.json",
  "voice_application_sid": null,
  "voice_caller_id_lookup": null,
  "voice_fallback_method": "POST",
  "voice_fallback_url": null,
  "voice_method": "POST",
  "voice_url": null,
  "verification_status": "Unverified"
}
```

## **Example**

```typescript {8}
import { RestClient } from "@signalwire/sdk";

const client = new RestClient({
  project: "your-project-id",
  token: "your-api-token",
  host: "your-space.signalwire.com"
});
const number = await client.compat.phoneNumbers.purchase({
  PhoneNumber: "+15551234567",
  FriendlyName: "Main Line"
});
```