Purchase Number/v1/numbers/{number}

Description

Assigns a selected number to the account.

POST
Endpoint

https://api.textport.com/v1/numbers/{number}

Sample Request Payload
{
    "Number": "12025551212",
    "LeasePeriod": "1"
}
<NumberRequest>
    <Number>12025551212</Number>
    <LeasePeriod>1</LeasePeriod>
</NumberRequest>
Code Examples (using JSON payload)
POST /v1/numbers HTTP/1.1
Host: https://api.textport.com
Content-Type: application/json
Authorization: Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn
{
"Number": "12025551212",
"LeasePeriod": "1"
}
var client = new RestClient("https://api.textport.com/v1/numbers");
var request = new RestRequest(Method.POST);

request.AddHeader("Authorization", "Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "{\n\t\"Number\": \"12025551212\",\n\t\"LeasePeriod\": \"1\"\n}", ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
$request = new HttpRequest();
$request->setUrl('https://api.textport.com/v1/numbers');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
    'Authorization' => 'Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn',
    'Content-Type' => 'application/json'
));

$request->setBody('{
    "Number": "12025551212",
    "LeasePeriod": "1"
}');

try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
    echo $ex;
}
curl -X POST \
    https://api.textport.com/v1/numbers \
    -H 'Authorization: Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn' \
    -H 'Content-Type: application/json' \
    -d '{
    "Number": "12025551212",
    "LeasePeriod": "1"
    }'
var settings = {
    "async": true,
    "crossDomain": true,
    "url": "https://api.textport.com/v1/numbers",
    "method": "POST",
    "headers": {
        "Content-Type": "application/json",
        "Authorization": "Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn"
    },
    "processData": false,
    "data": "{ \"Number\": \"12025551212\", \"LeasePeriod\": \"1\" }"
}

$.ajax(settings).done(function (response) {
    console.log(response);
});
import http.client

conn = http.client.HTTPConnection("https://api.textport.com/")

payload = "{ \"Number\": \"12025551212\", \"LeasePeriod\": \"1\" }"

headers = {
    'Content-Type': "application/json",
    'Authorization': "Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn"
}

conn.request("POST", "v1,numbers", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://api.textport.com/v1/numbers")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Authorization"] = 'Basic MS13OFBHczdPY09KOkVnbkJDZnh5N2txMXdHVkpycFJn'
request.body = "{ \"Number\": \"12025551212\", \"LeasePeriod\": \"1\" }"

response = http.request(request)
puts response.read_body
Response
{
    "Number": "12025551212",
    "Success": true,
    "ExpirationDate": "2019-08-20T01:04:57.9741555Z",
    "ProcessingMessage": "Number 12025551212 was successfully purchased for a 1 month period."
}
<NumberRequestResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Number>12025551212</Number>
    <Success>true</Success>
    <ExpirationDate>2019-08-20T00:57:11.5175842Z</ExpirationDate>
    <ProcessingMessage>Number 12025551212 was successfully purchased for a 1 month period.</ProcessingMessage>
</NumberRequestResult>

Note: The default format for response content is JSON. Adding an HTTP header Accept: application/xml will set the response format to XML.