> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# assign_phone_route

> Assign a phone route to a Fabric resource.

Assign a phone route to a Fabric resource.

### Schema

```yaml
openapi: 3.1.0
info:
  title: API
  version: 1.0.0
paths:
  /api/fabric/resources/{id}/phone_routes:
    post:
      operationId: subpackagePhoneRoutes_assign_resource_phone_route
      summary: Assign Resource to phone route
      description: >-
        Assigns an existing Fabric resource as a phone number's calling or
        messaging handler. Use it when inbound traffic to an owned number should
        run an AI Agent, script, Call Flow, Relay Application, or another
        resource. This operation does not purchase or import the number; use
        [Purchase phone
        number](/docs/apis/rest/phone-numbers/purchase-phone-number) or [Import
        phone
        number](/docs/apis/rest/phone-numbers/create-imported-phone-number)
        first when needed.


        #### Permissions


        The API token used to authenticate must have the following scope(s)
        enabled to make a successful request: _Voice_, _Messaging_, _Fax_, or
        _Video_.


        [Learn more about API scopes](/docs/platform/your-signalwire-api-space).
      tags:
        - subpackage_phoneRoutes
      parameters:
        - name: id
          in: path
          description: The unique identifier of the Resource.
          required: true
          schema:
            $ref: '#/components/schemas/uuid'
      responses:
        '201':
          description: >-
            The request has succeeded and a new resource has been created as a
            result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PhoneRouteResponse'
        '401':
          description: Access is unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode401'
        '404':
          description: The server cannot find the requested resource.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode404'
        '422':
          description: The request contains invalid parameters. See errors for details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PhoneRouteCreateStatusCode422'
        '500':
          description: An internal server error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Types.StatusCodes.StatusCode500'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PhoneRouteAssignRequest'
tags:
  - name: subpackage_phoneRoutes
servers:
  - url: https://%7BYour_Space_Name%7D.signalwire.com
    description: SignalWire API
components:
  schemas:
    uuid:
      type: string
      format: uuid
      description: Universal Unique Identifier.
      title: uuid
    UsedForType:
      type: string
      enum:
        - calling
        - messaging
      description: Sets the handler to handle incoming `calls` or `messages`.
      title: UsedForType
    PhoneRouteAssignRequest:
      type: object
      properties:
        phone_route_id:
          $ref: '#/components/schemas/uuid'
          description: The id of the phone route.
        handler:
          $ref: '#/components/schemas/UsedForType'
          description: >-
            Indicates if the resource should be assigned to a `calling` or
            `messaging` handler.
      required:
        - phone_route_id
        - handler
      title: PhoneRouteAssignRequest
    AudioChannel:
      type: object
      properties:
        audio:
          type: string
          description: Audio Channel of Fabric Address
      required:
        - audio
      title: AudioChannel
    MessagingChannel:
      type: object
      properties:
        messaging:
          type: string
          description: Messaging Channel of Fabric Address
      required:
        - messaging
      title: MessagingChannel
    VideoChannel:
      type: object
      properties:
        video:
          type: string
          description: Video Channel of Fabric Address
      required:
        - video
      title: VideoChannel
    AddressChannel:
      oneOf:
        - $ref: '#/components/schemas/AudioChannel'
        - $ref: '#/components/schemas/MessagingChannel'
        - $ref: '#/components/schemas/VideoChannel'
      title: AddressChannel
    PhoneRouteResponseType:
      type: string
      enum:
        - app
      description: The display type of a fabric address pointing to an application.
      title: PhoneRouteResponseType
    PhoneRouteResponse:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/uuid'
          description: Unique ID of the Fabric Address.
        name:
          type: string
          description: Name of the Fabric Address.
        display_name:
          type: string
          description: Display name of the Fabric Address.
        cover_url:
          type: string
          description: Cover url of the Fabric Address.
        preview_url:
          type: string
          description: Preview url of the Fabric Address.
        locked:
          type: boolean
          description: >-
            Locks the Fabric Address. This is used to prevent the Fabric Address
            from accepting calls.
        channels:
          $ref: '#/components/schemas/AddressChannel'
          description: Channels of the Fabric Address.
        created_at:
          type: string
          format: date-time
          description: Fabric Address Creation Date.
        type:
          $ref: '#/components/schemas/PhoneRouteResponseType'
          description: The display type of a fabric address pointing to an application.
      required:
        - id
        - name
        - display_name
        - cover_url
        - preview_url
        - locked
        - channels
        - created_at
        - type
      title: PhoneRouteResponse
    TypesStatusCodesStatusCode401Error:
      type: string
      enum:
        - Unauthorized
      title: TypesStatusCodesStatusCode401Error
    Types.StatusCodes.StatusCode401:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode401Error'
      required:
        - error
      description: Access is unauthorized.
      title: Types.StatusCodes.StatusCode401
    TypesStatusCodesStatusCode404Error:
      type: string
      enum:
        - Not Found
      title: TypesStatusCodesStatusCode404Error
    Types.StatusCodes.StatusCode404:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode404Error'
      required:
        - error
      description: The server cannot find the requested resource.
      title: Types.StatusCodes.StatusCode404
    Types.StatusCodes.RestApiErrorItem:
      type: object
      properties:
        type:
          type: string
          description: The category of error.
        code:
          type: string
          description: A specific error code.
        message:
          type: string
          description: A description of what caused the error.
        attribute:
          type:
            - string
            - 'null'
          description: The request parameter that caused the error, if applicable.
        url:
          type: string
          description: A link to documentation about this error.
      required:
        - type
        - code
        - message
        - url
      description: Details about a specific error.
      title: Types.StatusCodes.RestApiErrorItem
    PhoneRouteCreateStatusCode422:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Types.StatusCodes.RestApiErrorItem'
          description: List of validation errors.
      required:
        - errors
      description: The request contains invalid parameters. See errors for details.
      title: PhoneRouteCreateStatusCode422
    TypesStatusCodesStatusCode500Error:
      type: string
      enum:
        - Internal Server Error
      title: TypesStatusCodesStatusCode500Error
    Types.StatusCodes.StatusCode500:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/TypesStatusCodesStatusCode500Error'
      required:
        - error
      description: An internal server error occurred.
      title: Types.StatusCodes.StatusCode500

```

## **Response Example**

### Response (201)

```json
{
  "id": "691af061-cd86-4893-a605-173f47afc4c2",
  "name": "justice-league",
  "display_name": "Justice League",
  "cover_url": "https://coverurl.com",
  "preview_url": "https://previewurl.com",
  "locked": true,
  "channels": {
    "audio": "/external/resource_name?channel=audio"
  },
  "created_at": "2024-05-06T12:20:00Z",
  "type": "app"
}
```

## **Example**

```python {9}
from signalwire.rest import RestClient

client = RestClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
)

result = client.fabric.resources.assign_phone_route(
    "resource-id", phone_route_id="route-uuid", handler="calling",
)
print(f"Phone route assigned: {result['id']}")
```