Get and Purchase a Phone Number

The first step is to buy a local Seattle phone number. In order to do this, you need to find out if there are any available phone numbers to buy, and if so, what they are. To do this, submit a GET request to the /v1/available-tns/tns/ collection resource and include parameters for Seattle in the URL request. The request should resemble the following:

GET /v1/available-tns/tns/?page=1&limit=1&state=WA&ratecenter=SEATTLEX-Timestamp: ...
Authorization: ...
Accept: application/json

            
In the previous GET example, a limit of one(1) phone number was set to be returned for the results; however, you can set any number up to 200.

A successful GET request will then send a response that includes the requested information. In this example, an available Seattle number, 12066418000, is returned:

Python
{"tns":  {"12066418000":
    {
      "billing_methods": ["METERED"], 
      "initial_cost": "1.00",
      "monthly_cost": "1.25",
      "ratecenter": "Seattle",
      "state": "WA"
    }
  }
}

            

If multiple numbers were set for the limit, information for each available number based on the limit would be returned.

In order to purchase this phone number, next submit a PUT request to the /v1/tns/(str: telephone_number) entity resource. When buying a phone number, there is only one option for the billing method:

  • METERED, which are unlimited concurrent calls, each billed per-minute used. The PUT request should resemble the following, with the selected number included in the request:

The PUT request should resemble the following, with the selected number included in the request:

Python
PUT /v1/tns/12066418000 HTTP/1.1X-Timestamp: ...
Authorization: Basic ... 
Content-Type: application/json

{"billing_method": "METERED"}

            

A successful request will then send the following response:

Python
HTTP/1.1 201 Created
            

Route the New Phone Number

You can now set up the newly purchased Seattle phone number to route to a phone in New York.

The first step is to set up a route that points to the main phone number in New York. To do this, submit a PUT request to the /v1/routes/(str: route_name) entity resource that includes:

  • the route_name. For this example, use newyork_shop.
  • the routetype. A type can be HOST, PSTN, or URI. Since this is to a phone number, the type should be PSTN.
  • the route_name. For this example, use newyork_shop.
  • the route value, which is the destination of the route for the New York phone number. For this example, the destination route is 12125550000.

The PUT request should then resemble the following:

Python
PUT /v1/routes/newyork_shop HTTP/1.1X-Timestamp: ...
Authorization: Basic ... 
Content-Type: application/json

{"type": "PSTN", "value": "12125550000"}

            

A successful PUT request will then return the following response:

Python
HTTP/1.1 201 Created
            

With the Seattle number now routed to the New York phone number, the last step is to apply the route to the phone number.

A route is applied by submitting a PATCH request to the /v1/tns/(str: telephone_number)entity resource and including a routes preference in the query parameters. A routes preference sets both the primary route as well as a secondary route to use if the primary route is unavailable. Since both primary and secondary routes must be listed, set newyork_shop as the primary route and set a route named sip-reg as the secondary route.

sip-reg is a default route on every Flowroute account.

The PATCH request should then resemble the following:

Python
PATCH /v1/tns/12066418000 HTTP/1.1X-Timestamp: ...
Authorization: Basic ... 
Content-Type: application/json

{"routes": [{"name": "newyork_shop"}, {"name": "sip-reg"}]}

            

A successful PATCH request will return the following response:

Python

HTTP/1.1 204 No Content

            

Test the New Phone Number

To test that everything was set up correctly, place a call to the purchased Seattle phone number. The call you place should automatically be forwarded to the destination New York phone number.

If you run into any issues, please contact Flowroute Support.