> This page is for APIs.

> 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.

# Import phone number

POST https://%7BYour_Space_Name%7D.signalwire.com/api/relay/rest/imported_phone_numbers
Content-Type: application/json

Imports a phone number that remains hosted with another provider into the SignalWire project and enables the requested capabilities. Use this Partner API when bringing externally hosted inventory; use [Purchase phone number](/docs/apis/rest/phone-numbers/purchase-phone-number) for SignalWire inventory, or Compatibility [Import phone number](/docs/compatibility-api/rest/imported-phone-numbers/create-imported-phone-number) for a form-encoded request.

**Note:** This is a **Partner API**. To enable it on your SignalWire Space, contact [Sales](https://signalwire.com/company/contact?utm_campaign=devex_sent_em).

#### 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).

Reference: https://signalwire.com/docs/apis/rest/phone-numbers/create-imported-phone-number

## Authentication

- `Authorization` header (basic auth, required) — SignalWire Basic Authentication using Project ID and API Token. The client sends HTTP requests with the Authorization header containing the word Basic followed by a space and a base64-encoded string of project_id:token. The project ID will be used as the username and the API token as the password. Example: ``` Authorization: Basic base64(project_id:token) ```

## Request

### Body (application/json)

This endpoint expects an ImportPhoneNumberRequest.

- `number` (string, required) — The phone number to import in E.164 format. Number must be between 5 and 30 characters with no special characters besides a leading +.
- `number_type` (enum, required) — The type of phone number being imported.
  - Allowed values: `longcode`, `tollfree`
- `capabilities` (list of enum, optional) — The capabilities to enable for this phone number. Can include any combination of SMS, Voice, Fax, and MMS. If not provided, defaults to all capabilities.
  - Allowed values: `sms`, `voice`, `fax`, `mms`

## Response

### 201

The request has succeeded and a new resource has been created as a result.

- `id` (string, required) — The unique identifier of the phone number.
- `number` (string, required) — The phone number in E.164 format.
- `name` (string, required, nullable) — The name given to the phone number. Helps to distinguish different phone numbers within your project.
- `capabilities` (list of enum, required) — A list of communication methods this phone number supports.
  - Allowed values: `voice`, `sms`, `mms`, `fax`
- `number_type` (enum, required) — The type of number this is defined as.
  - Allowed values: `toll-free`, `longcode`
- `e911_address_id` (string, required, nullable) — The E911 address ID associated with this phone number.
- `e911_status` (enum, required, nullable) — The E911 provisioning status for this phone number. `null` when the number has never had an E911 address assigned. Once an address is assigned the value is `pending` while the carrier processes the order, then `active` once the carrier confirms the registration, or `failed` if the carrier does not confirm it. Removing the address sets `pending_removal`, and the value becomes `unregistered` once the carrier confirms the removal.
  - Allowed values: `pending`, `active`, `failed`, `pending_removal`, `unregistered`
- `cnam` (string, required, nullable) — The caller ID name currently applied at the carrier for this phone number, or `null` when none is set. This is the name call recipients can see. Change it with [Request a caller ID name](/docs/apis/rest/caller-id-name/request-caller-id-name). This value changes only after a request is approved and applied at the carrier, so it can differ from the requested `name` while a request is being reviewed or after one is rejected or fails.
- `created_at` (datetime, required) — The date the number was added to your project.
- `updated_at` (datetime, required) — The date the number was last updated.
- `next_billed_at` (datetime, required, nullable) — The next date the number will be billed for.
- `call_handler` (enum, required, nullable) — What type of handler you want to run on inbound calls.
  - Allowed values: `relay_context`, `relay_topic`, `relay_script`, `relay_application`, `relay_connector`, `relay_sip_endpoint`, `relay_verto_endpoint`, `laml_webhooks`, `laml_application`, `dialogflow`, `video_room`, `call_flow`, `ai_agent`, `fabric_subscriber`, `sip_gateway`, `call_queue`
- `calling_handler_resource_id` (string, required, nullable) — The unique identifier of the calling handler resource.
- `call_receive_mode` (enum, required) — How do you want to receive the incoming call.
  - Allowed values: `voice`, `fax`
- `call_request_url` (string, required, nullable) — The URL to make a request to when using the laml_webhooks call handler.
- `call_request_method` (enum, required, nullable) — The HTTP method to use when making a request to the call_request_url.
  - Allowed values: `GET`, `POST`
- `call_fallback_url` (string, required, nullable) — The fallback URL to make a request to when using the laml_webhooks call handler and the call_request_url fails.
- `call_fallback_method` (enum, required, nullable) — The HTTP method to use when making a request to the call_fallback_url.
  - Allowed values: `GET`, `POST`
- `call_status_callback_url` (string, required, nullable) — The URL to make status callbacks to when using the laml_webhooks call handler.
- `call_status_callback_method` (enum, required, nullable) — The HTTP method to use when making a request to the call_status_callback_url.
  - Allowed values: `GET`, `POST`
- `call_laml_application_id` (string, required, nullable) — The ID of the LaML Application to use when using the laml_application call handler.
- `call_dialogflow_agent_id` (string, required, nullable) — The ID of the Dialogflow Agent to start when using the dialogflow call handler.
- `call_relay_topic` (string, required, nullable) — A string representing the Relay topic to forward incoming calls to. This is only used (and required) when call_handler is set to relay_topic.
- `call_relay_topic_status_callback_url` (string, required, nullable) — A string representing a URL to send status change messages to. This is only used (and required) when call_handler is set to relay_topic.
- `call_relay_script_url` (string, required, nullable) — The URL to make a request to when using the relay_script call handler. The URL must respond with a valid SWML script.
- `call_relay_context` (string, required, nullable) — The name of the Relay Context to send this call to when using the relay_context call handler.
- `call_relay_context_status_callback_url` (string, required, nullable) — A string representing a URL to send status change messages to. This is only used (and required) when call_handler is set to relay_context.
- `call_relay_application` (string, required, nullable) — The name of the Relay Application to send this call to when using the relay_application call handler.
- `call_relay_connector_id` (string, required, nullable) — The ID of the Relay Connector to send this call to when using the relay_connector call handler.
- `call_sip_endpoint_id` (string, required, nullable) — The ID of the Relay SIP Endpoint to send this call to when using the relay_sip_endpoint call handler.
- `call_verto_resource` (string, required, nullable) — The name of the Verto Relay Endpoint to send this call to when using the relay_verto_endpoint call handler.
- `call_video_room_id` (string, required, nullable) — The ID of the Video Room to send this call to when using the video_room call handler.
- `message_handler` (enum, required, nullable) — What type of handler you want to run on inbound messages.
  - Allowed values: `relay_context`, `relay_topic`, `relay_application`, `laml_webhooks`, `laml_application`
- `messaging_handler_resource_id` (string, required, nullable) — The unique identifier of the messaging handler resource.
- `message_request_url` (string, required, nullable) — The URL to make a request to when using the laml_webhooks message handler.
- `message_request_method` (enum, required, nullable) — The HTTP method to use when making a request to the message_request_url.
  - Allowed values: `GET`, `POST`
- `message_fallback_url` (string, required, nullable) — The fallback URL to make a request to when using the laml_webhooks message handler and the message_request_url fails.
- `message_fallback_method` (enum, required, nullable) — The HTTP method to use when making a request to the message_fallback_url.
  - Allowed values: `GET`, `POST`
- `message_laml_application_id` (string, required, nullable) — The ID of the LaML Application to use when using the laml_application message handler.
- `message_relay_topic` (string, required, nullable) — The name of the Relay Topic to send this message to when using the relay_topic message handler.
- `message_relay_context` (string, required, nullable) — The name of the Relay Context to send this message to when using the relay_context message handler.
- `country_code` (string, required, nullable) — The ISO 3166-1 alpha-2 country code of the phone number.
- `pending_port_in` (boolean, required) — `true` while the number is being ported into your account. A number that is porting in can't be assigned to a 10DLC campaign until the port completes.

## Errors

### 422 Unprocessable Entity Error

The request failed validation. See errors for details.

- `errors` (list of Types.StatusCodes.SpaceApiErrorItem, required) — List of validation errors.

### 500 Internal Server Error

An internal server error occurred.

- `error` (enum, required)
  - Allowed values: `Internal Server Error`

## Types

### Types.StatusCodes.SpaceApiErrorItem

Details about a specific validation error.

- `detail` (string, required) — A description of what caused the error.
- `status` (string, required) — The HTTP status code.
- `title` (string, required) — A short summary of the error type.
- `code` (string, required) — The error code.

## Examples

**Request**

```json
{
  "number": "+49152234333323",
  "number_type": "longcode"
}
```

**Response**

```json
{
  "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "number": "+15558675309",
  "name": "Jenny",
  "capabilities": [
    "voice"
  ],
  "number_type": "toll-free",
  "e911_address_id": "string",
  "e911_status": "active",
  "cnam": "ACME PLUMBING",
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "next_billed_at": "2024-01-15T09:30:00Z",
  "call_handler": "relay_context",
  "calling_handler_resource_id": "fe4093d9-58c2-4931-b4b9-5679f82652c6",
  "call_receive_mode": "voice",
  "call_request_url": "string",
  "call_request_method": "POST",
  "call_fallback_url": "string",
  "call_fallback_method": "POST",
  "call_status_callback_url": "string",
  "call_status_callback_method": "POST",
  "call_laml_application_id": "string",
  "call_dialogflow_agent_id": "string",
  "call_relay_topic": "office",
  "call_relay_topic_status_callback_url": "https://myapplication/handle_relay_callbacks",
  "call_relay_script_url": "https://example.signalwire.com/relay-bins/60e2ba7b-366e-44de-84e3-0c76cfccf1cc",
  "call_relay_context": "my_relay_app",
  "call_relay_context_status_callback_url": "https://myapplication/handle_relay_callbacks",
  "call_relay_application": "my_relay_app",
  "call_relay_connector_id": "string",
  "call_sip_endpoint_id": "string",
  "call_verto_resource": "string",
  "call_video_room_id": "fe4093d9-58c2-4931-b4b9-5679f82652c6",
  "message_handler": "relay_application",
  "messaging_handler_resource_id": "fe4093d9-58c2-4931-b4b9-5679f82652c6",
  "message_request_url": "string",
  "message_request_method": "POST",
  "message_fallback_url": "string",
  "message_fallback_method": "POST",
  "message_laml_application_id": "string",
  "message_relay_topic": "string",
  "message_relay_context": "my_relay_app",
  "country_code": "US",
  "pending_port_in": false
}
```

**SDK Code**

```python
import requests

url = "https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers"

payload = {
    "number": "+49152234333323",
    "number_type": "longcode"
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<project_id>", "<api_token>"))

print(response.json())
```

```javascript
const url = 'https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers';
const credentials = btoa("<project_id>:<api_token>");

const options = {
  method: 'POST',
  headers: {
    Authorization: `Basic ${credentials}`,
    'Content-Type': 'application/json'
  },
  body: '{"number":"+49152234333323","number_type":"longcode"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers"

	payload := strings.NewReader("{\n  \"number\": \"+49152234333323\",\n  \"number_type\": \"longcode\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<project_id>", "<api_token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<project_id>", "<api_token>")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"number\": \"+49152234333323\",\n  \"number_type\": \"longcode\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers")
  .basicAuth("<project_id>", "<api_token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"number\": \"+49152234333323\",\n  \"number_type\": \"longcode\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers', [
  'body' => '{
  "number": "+49152234333323",
  "number_type": "longcode"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<project_id>', '<api_token>'],
]);

echo $response->getBody();
```

```csharp
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers");
client.Authenticator = new HttpBasicAuthenticator("<project_id>", "<api_token>");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"number\": \"+49152234333323\",\n  \"number_type\": \"longcode\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let credentials = Data("<project_id>:<api_token>".utf8).base64EncodedString()

let headers = [
  "Authorization": "Basic \(credentials)",
  "Content-Type": "application/json"
]
let parameters = [
  "number": "+49152234333323",
  "number_type": "longcode"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://{your_space_name}.signalwire.com/api/relay/rest/imported_phone_numbers")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```