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

# Create an associated phone number

> Creates a new associated phone number for a porting order. This is used for partial porting in GB to specify which phone numbers should be kept or disconnected.



## OpenAPI

````yaml https://telnyx-openapi-ng.s3.us-east-1.amazonaws.com/numbers-identity/porting-phone-numbers.yml post /porting_orders/{porting_order_id}/associated_phone_numbers
openapi: 3.1.0
info:
  title: Telnyx Porting Phone Numbers API
  version: 2.0.0
  description: API for porting phone numbers, blocks, extensions, and configurations.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
security:
  - bearerAuth: []
paths:
  /porting_orders/{porting_order_id}/associated_phone_numbers:
    post:
      tags:
        - Porting Orders
      summary: Create an associated phone number
      description: >-
        Creates a new associated phone number for a porting order. This is used
        for partial porting in GB to specify which phone numbers should be kept
        or disconnected.
      operationId: createPortingAssociatedPhoneNumber
      parameters:
        - name: porting_order_id
          in: path
          description: Identifies the Porting Order associated with the phone number
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        $ref: '#/components/requestBodies/CreatePortingAssociatedPhoneNumber'
      responses:
        '201':
          $ref: '#/components/responses/ShowPortingAssociatedPhoneNumber'
        '404':
          description: Not found
        '422':
          description: Unprocessable entity. Check message field in response for details.
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Telnyx from 'telnyx';


            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });


            const associatedPhoneNumber = await
            client.portingOrders.associatedPhoneNumbers.create(
              '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
              {
                action: 'keep',
                phone_number_range: {},
              },
            );


            console.log(associatedPhoneNumber.data);
        - lang: Python
          source: >-
            import os

            from telnyx import Telnyx


            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )

            associated_phone_number =
            client.porting_orders.associated_phone_numbers.create(
                porting_order_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                action="keep",
                phone_number_range={},
            )

            print(associated_phone_number.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tassociatedPhoneNumber, err := client.PortingOrders.AssociatedPhoneNumbers.New(\n\t\tcontext.TODO(),\n\t\t\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\",\n\t\ttelnyx.PortingOrderAssociatedPhoneNumberNewParams{\n\t\t\tAction:           telnyx.PortingOrderAssociatedPhoneNumberNewParamsActionKeep,\n\t\t\tPhoneNumberRange: telnyx.PortingOrderAssociatedPhoneNumberNewParamsPhoneNumberRange{},\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", associatedPhoneNumber.Data)\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.portingorders.associatedphonenumbers.AssociatedPhoneNumberCreateParams;

            import
            com.telnyx.sdk.models.portingorders.associatedphonenumbers.AssociatedPhoneNumberCreateResponse;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    AssociatedPhoneNumberCreateParams params = AssociatedPhoneNumberCreateParams.builder()
                        .portingOrderId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
                        .action(AssociatedPhoneNumberCreateParams.Action.KEEP)
                        .phoneNumberRange(AssociatedPhoneNumberCreateParams.PhoneNumberRange.builder().build())
                        .build();
                    AssociatedPhoneNumberCreateResponse associatedPhoneNumber = client.portingOrders().associatedPhoneNumbers().create(params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            associated_phone_number =
            telnyx.porting_orders.associated_phone_numbers.create(
              "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              action: :keep,
              phone_number_range: {}
            )


            puts(associated_phone_number)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $associatedPhoneNumber = $client
                ->portingOrders
                ->associatedPhoneNumbers
                ->create(
                '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
                action: 'keep',
                phoneNumberRange: [
                  'endAt' => '+441234567899', 'startAt' => '+441234567890'
                ],
              );

              var_dump($associatedPhoneNumber);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx porting-orders:associated-phone-numbers create \
              --api-key 'My API Key' \
              --porting-order-id 182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e \
              --action keep \
              --phone-number-range '{}'
components:
  requestBodies:
    CreatePortingAssociatedPhoneNumber:
      required: true
      content:
        application/json:
          schema:
            type: object
            required:
              - phone_number_range
              - action
            properties:
              phone_number_range:
                type: object
                properties:
                  start_at:
                    description: >-
                      Specifies the start of the phone number range for this
                      associated phone number.
                    type: string
                    pattern: ^\+\d{7,15}$
                    example: '+441234567890'
                  end_at:
                    description: >-
                      Specifies the end of the phone number range for this
                      associated phone number.
                    type: string
                    pattern: ^\+\d{7,15}$
                    example: '+441234567899'
              action:
                description: >-
                  Specifies the action to take with this phone number during
                  partial porting.
                type: string
                enum:
                  - keep
                  - disconnect
                example: keep
  responses:
    ShowPortingAssociatedPhoneNumber:
      description: Successful response
      content:
        application/json:
          schema:
            type: object
            properties:
              data:
                $ref: '#/components/schemas/PortingAssociatedPhoneNumber'
  schemas:
    PortingAssociatedPhoneNumber:
      type: object
      properties:
        id:
          description: Uniquely identifies this associated phone number.
          type: string
          format: uuid
          example: f24151b6-3389-41d3-8747-7dd8c681e5e2
          readOnly: true
        porting_order_id:
          description: Identifies the porting order associated with this phone number.
          type: string
          format: uuid
          example: a24151b6-3389-41d3-8747-7dd8c681e5e2
        country_code:
          description: >-
            Specifies the country code for this associated phone number. It is a
            two-letter ISO 3166-1 alpha-2 country code.
          type: string
          example: GB
        phone_number_type:
          description: Specifies the phone number type for this associated phone number.
          type: string
          example: local
          enum:
            - landline
            - local
            - mobile
            - national
            - shared_cost
            - toll_free
        phone_number_range:
          description: Specifies the phone number range for this associated phone number.
          type: object
          properties:
            start_at:
              description: >-
                Specifies the start of the phone number range for this
                associated phone number.
              type: string
              pattern: ^\+\d{7,15}$
              example: '+441234567890'
            end_at:
              description: >-
                Specifies the end of the phone number range for this associated
                phone number.
              type: string
              pattern: ^\+\d{7,15}$
              example: '+441234567899'
        action:
          description: >-
            Specifies the action to take with this phone number during partial
            porting.
          type: string
          enum:
            - keep
            - disconnect
          example: keep
        record_type:
          type: string
          example: porting_associated_phone_number
          description: Identifies the type of the resource.
          readOnly: true
        created_at:
          type: string
          format: date-time
          description: ISO 8601 formatted date indicating when the resource was created.
          example: '2021-03-19T10:07:15.527Z'
          readOnly: true
        updated_at:
          type: string
          format: date-time
          description: >-
            ISO 8601 formatted date indicating when the resource was last
            updated.
          example: '2021-03-19T10:07:15.527Z'
          readOnly: true
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````