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

# Move Phone Number to Environment

> Sets which environment one of the agent's phone numbers answers from. `dev` and `staging` need deployments on for the agent. If the environment already has a number, the request is refused (409) rather than taking that line off the agent. To assign a number to an agent in the first place, use the phone number assign endpoint, which also takes `environmentId`.



## OpenAPI

````yaml /api-reference/openapi.json put /v2/voice-agents/{voiceAgentId}/phone-numbers/{phoneNumberId}/environment
openapi: 3.0.1
info:
  title: Hamsa API
  description: >-
    The Hamsa API: voice agents and their calls, phone numbers, batch calls and
    knowledge bases; speech to text, text to speech, voices and AI content.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.tryhamsa.com
security: []
paths:
  /v2/voice-agents/{voiceAgentId}/phone-numbers/{phoneNumberId}/environment:
    put:
      summary: Move a phone number to an environment
      description: >-
        Sets which environment one of the agent's phone numbers answers from.
        `dev` and `staging` need deployments on for the agent. If the
        environment already has a number, the request is refused (409) rather
        than taking that line off the agent. To assign a number to an agent in
        the first place, use the phone number assign endpoint, which also takes
        `environmentId`.
      parameters:
        - in: path
          name: voiceAgentId
          required: true
          description: ID of the voice agent.
          schema:
            type: string
            format: uuid
            example: d949f13f-40d2-4e48-ac86-b66633070603
        - in: path
          name: phoneNumberId
          required: true
          description: ID of a phone number assigned to the agent.
          schema:
            type: string
            format: uuid
            example: c7e5a3b1-9d8f-4e6c-a2b4-1f3e5d7c9a0b
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - environmentId
              properties:
                environmentId:
                  type: string
                  format: uuid
                  nullable: true
                  description: >-
                    The environment to answer from. `null` (or prod's ID) for
                    `prod`.
                  example: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
            examples:
              staging:
                summary: Answer from staging
                value:
                  environmentId: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
              prod:
                summary: Back to prod
                value:
                  environmentId: null
      responses:
        '200':
          description: Moved. Returns the number and its environment.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: success
                  data:
                    $ref: '#/components/schemas/AgentEnvironmentNumberBinding'
        '400':
          description: Invalid body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '401':
          description: 'Unauthorized: missing or invalid API key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: >-
            Your API key or role does not have the `agents:manage_channels`
            permission.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '404':
          description: >-
            Voice agent not found, the number is not assigned to this agent, or
            the environment is not on this agent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '409':
          description: >-
            The environment already has a phone number on this agent
            (`EnvironmentHasNumber`; `params.environment` and
            `params.phoneNumberId` name it).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '422':
          description: >-
            Deployments are off for this agent, so the number can only answer
            from `prod` (`NotAllowedInState`, `params.reason` `VERSIONING_OFF`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '500':
          description: Server Side Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    AgentEnvironmentNumberBinding:
      type: object
      properties:
        phoneNumberId:
          type: string
          format: uuid
          example: c7e5a3b1-9d8f-4e6c-a2b4-1f3e5d7c9a0b
        number:
          type: string
          example: '+14155550100'
        label:
          type: string
          example: Support line
        agentId:
          type: string
          format: uuid
          example: d949f13f-40d2-4e48-ac86-b66633070603
        environmentId:
          type: string
          format: uuid
          nullable: true
          description: Environment the number answers from. `null` means `prod`.
          example: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
        environment:
          type: string
          enum:
            - dev
            - staging
            - prod
          description: Name of that environment.
          example: staging
    ErrorSchema:
      type: object
      properties:
        code:
          type: integer
          description: >-
            Service error code: the HTTP status with a service prefix (for
            example `8404`). Missing when the service has no code for that
            status.
          example: 8404
        message:
          type: string
          description: >-
            What went wrong. Some services (calls and recordings) put the error
            key here, for example `CallNotFoundOrUnavailable`, and send no
            `messageKey`.
          example: Policy not found!
        messageKey:
          type: string
          description: >-
            Stable key for the error, safe to match on in code. Not returned by
            every service.
          example: PolicyNotFound
        params:
          type: object
          additionalProperties: true
          description: >-
            Details for some errors (for example `reason`). Not returned by
            every service.
          example:
            reason: NO_DRAFT
    AgentEnvironmentError:
      type: object
      properties:
        code:
          type: integer
          example: 8409
        message:
          type: string
          example: >-
            This environment or the A/B split changed since you last looked.
            Review the current state and try again.
        messageKey:
          type: string
          example: ReleaseStale
        params:
          type: object
          additionalProperties: true
          description: Details for the error, such as `reason`.
          example:
            reason: STALE
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Pass the API key in the Authorization header, You need to put Token
        keyword before the API key. e.g. 'Authorization: Token <api-key>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.