HTTP/1.1 404 Not Found
Server: nginx/1.2.7
Date: Fri, 18 Jan 2017 16:14:30 GMT
Content-Type: application/json
Connection: keep-alive
Vary: Content-Type
Content-Length: 2675
X-Catalyst-Version: 5.90112
X-SureVoIP-API-Auth-User: XXX
X-SureVoIP-API-Version: 3.50
{
"error":"Cannot find what you were looking for!"
}
If you are creating (POST) or updating (PUT) resources and there is an error with your data, we will return:
HTTP/1.1 400 Bad Request
Server: nginx/1.2.7
Date: Fri, 18 Jan 2017 16:26:59 GMT
Content-Type: application/json
Connection: keep-alive
Vary: Content-Type
Content-Length: 2703
X-Catalyst-Version: 5.90112
X-SureVoIP-API-Auth-User: XXX
X-SureVoIP-API-Version: 3.50
{
"errors":[
{
"message":[
"Format is 447123123456. No + allowed"
],
"field":"to"
},
{
"message":[
"Must not contain spaces",
"Must be made up of letters, digits, and underscores"
],
"field":"from"
},
{
"message":[
"Message field is required"
],
"field":"message"
}
]
}
===== gzip =====
Responses can be gzip-encoded on demand. This is nice if your bandwidth is limited, or if big results are causing performance issues.
To enable gzip, simply add the following header to your request:
Accept-Encoding: gzip
**Note: this is currently being tested and may not be available**
====== Limits ======
The SureVoIP API has usage limits to avoid individual rampant applications degrading the overall user experience. We limit requests to **5000 per hour**. This is keyed off either your login, your OAuth 2.0 token, or request IP. You can check the returned HTTP headers of any API request to see your current status:
The response headers are:
X-SureVoIP-API-RateLimit-Limit
X-SureVoIP-API-RateLimit-Remaining
X-SureVoIP-API-RateLimit-TimeToReset
X-SureVoIP-API-RateLimit-TimeToResetSecs
An example of the values of these headers:
X-SureVoIP-API-RateLimit-Limit: 5000
X-SureVoIP-API-RateLimit-Remaining: 4966
X-SureVoIP-API-RateLimit-TimeToReset: 55 mins 10 secs
X-SureVoIP-API-RateLimit-TimeToResetSecs: 3310
If you feel restricted by these limits, please feel free to contact SureVoIP support and request a **paid for** higher limit. The limits are primarily here to protect the system from poorly coded applications, not to restrict you as a user/customer.
**Note: this is currently being tested and may not be present**
====== Authentication ======
Authentication is needed in order to use the SureVoIP API, and for this a [[http://www.surevoip.co.uk|SureVoIP]] account is required.
===== Basic Authentication ====
The credentials used for accessing the API via [[http://en.wikipedia.org/wiki/Basic_access_authentication|Basic Authentication]] (encrypted over HTTPS) are the same used to access the SureVoIP control panel - in other words your control panel username and password. We only support **HTTPS**.
This type of authentication method is good for apps that are only used from one place and testing via your browser.
You will provide your credentials every time you make a request. No sessions are used.
See the [[api_documentation#sandbox_play_area|Sandbox/Play area]] for more info.
===== OAuth 2.0 protocol =====
SureVoIP's RESTful API uses the [[http://oauth.net/2//|OAuth 2.0]] protocol for authentication and security. SureVoIP acts as an OAuth 2.0 provider, and all SureVoIP applications act as corresponding OAuth 2.0 consumers. All communications with SureVoIP as an OAuth 2.0 provider is via SSL, as OAuth 2.0 does not provide for token encryption.
SureVoIP provides several different authentication models for granting access to SureVoIP services. These models are discussed in more detail in the documentation sections that follow (when this work is finished and released on [[http://github.com|GitHub]] and [[http://search.cpan.org|the CPAN]] [[http://www.opensource.org|Open Source]] when the docs are written).
{{:oauth2.0_diagrams.pdf|OAuth 2 Flowcharts}}
====== Getting Started ======
You can test the [[api_documentation#resources|resources]] straight away, even with out authentication. The following resources can be used to answer these questions:
* can I talk to the SureVoIP API at all? This is covered by [[https://api.surevoip.co.uk/support/ip-address|support/ip-address]] and [[https://api.surevoip.co.uk/support/service-status|support/service-status]]
* can I accurately send and receive data, including accounting for Unicode/decode/encode issues? This covered by [[https://api.surevoip.co.uk|support/echo]]
* can I authenticate? This covered by any resource that requires authentication, for example: [[https://api.surevoip.co.uk/customers|customers]]
Helpful support resources:
* echo: [[https://api.surevoip.co.uk/support/echo]] (POST and PUT only)
* ip-address: [[https://api.surevoip.co.uk/support/ip-address]] (GET)
* service-status: [[https://api.surevoip.co.uk/support/service-status]] (GET)
====== Code Examples ======
We are slowly adding various code examples to the [[https://github.com/suretec/SureVoIP-API-Examples|SureVoIP API Examples]] GitHub repo.
Please check there from time to time.
====== Event notification and WebHooks ======
This work is currently being worked on and when finished will be released on [[http://github.com|GitHub]] and [[http://search.cpan.org|the CPAN]] [[http://www.opensource.org|Open Source]]). We'll send out an email and [[http://www.surevoip.co.uk/blog|blog post]] when ready.
====== RESTful Resources ======
The following sections describe in detail the resources available, what you can send, what [[api_documentation#response_formats|formats]] you can expect to receive from the SureVoIP API all using the uniform HTTP interface. There are also examples you can copy and paste for use with [[http://curl.haxx.se/|curl]].
For a complete list of resources and response codes etc. please see the [[api_documentation#response_codes|Response Codes]] table.
By default you will see [[http://en.wikipedia.org/wiki/Hypermedia|hypermedia]] that shows you what the available top level resources are, therefore running:
curl -i https://api.surevoip.co.uk/ -H 'Content-Type: application/json'
returns:
HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Fri, 18 Jan 2017 16:43:11 GMT
Content-Type: application/json
Connection: keep-alive
Vary: Content-Type
Content-Length: 656
X-Catalyst-Version: 5.90112
X-SureVoIP-API-Version: 3.50
{
"resources":{
"calls":"https://api.surevoip.co.uk/calls",
"sms":"https://api.surevoip.co.uk/sms",
"numbers":"https://api.surevoip.co.uk/numbers",
"contact":"https://api.surevoip.co.uk/contact",
"sip":"https://api.surevoip.co.uk/sip",
"partners":"https://api.surevoip.co.uk/partners",
"faxes":"https://api.surevoip.co.uk/faxes",
"areacodes":"https://api.surevoip.co.uk/numbers/areacodes",
"service-status":"https://api.surevoip.co.uk/support/service-status",
"porting":"https://api.surevoip.co.uk/porting",
"customers":"https://api.surevoip.co.uk/customers",
"ip-address":"https://api.surevoip.co.uk/support/ip-address",
"echo":"https://api.surevoip.co.uk/support/echo",
"billing":"https://api.surevoip.co.uk/billing"
}
}
===== List resources =====
All list resources support:
The following GET query string parameters allow you to limit the list returned. Note, parameters are case-sensitive and we also support [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html|Conditional GET]] and dates are in [[http://search.cpan.org/~drolsky/DateTime-Format-Strptime-1.5000/lib/DateTime/Format/Strptime.pm|strptime format]]:
^ Parameter ^ Description ^
|page|which page you'd like|
|offset|Where to start from|
|limit|Give me only this amount of results|
The following hypermedia will also be present:
{
"resources":{
"calls":"https://api.surevoip.co.uk/calls",
"sms":"https://api.surevoip.co.uk/sms",
"numbers":"https://api.surevoip.co.uk/numbers",
"contact":"https://api.surevoip.co.uk/contact",
"sip":"https://api.surevoip.co.uk/sip",
"partners":"https://api.surevoip.co.uk/partners",
"faxes":"https://api.surevoip.co.uk/faxes",
"areacodes":"https://api.surevoip.co.uk/numbers/areacodes",
"service-status":"https://api.surevoip.co.uk/support/service-status",
"porting":"https://api.surevoip.co.uk/porting",
"customers":"https://api.surevoip.co.uk/customers",
"ip-address":"https://api.surevoip.co.uk/support/ip-address",
"billing":"https://api.surevoip.co.uk/billing"
},
"entries_per_page":50,
"last_page":239,
"current_page":1,
"page_links":[
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls?page=1&limit=50&offset=0",
"title":"first_page"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls?page=1&limit=50&offset=0",
"title":"previous_page"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls?page=1&limit=50&offset=0",
"title":"current_page"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls?page=2&limit=50&offset=0",
"title":"next_page"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls?page=239&limit=50&offset=0",
"title":"last_page"
}
],
"next_page":2,
"previous_page":null,
"total_entries":"11941",
"first_page":1,
"limit":50,
"offset":0,
"list":[
{
....
},
{
....
},
{
....
}
]
}
===== Partners =====
Partner resources are the same as customer resources, but live at:
https://api.surevoip.co.uk/partners/{partner_name}/customers/{customer_name}/calls
etc.
Partners can provision their own customers, customer numbers, allocate them and various other things.
===== Customers =====
==== Your account ====
Your own customer account can be accessed by authenticating as a direct customer to the top level customer resource:
curl -i -X GET -u username:password https://api.surevoip.co.uk/customers
This would return a Location header, **302 Found** and a link to your account:
HTTP/1.1 302 Found
Server: nginx/1.0.14
Date: Fri, 18 Jan 2017 10:42:03 GMT
Content-Type: application/json
Connection: keep-alive
Location: https://api.surevoip.co.uk/customers/{account}
Vary: Content-Type
Content-Length: 2802
X-Catalyst: 5.90011
X-SureVoIP-API-Auth-User: XXX
X-SureVoIP-API-Version: 3.50
{
"resources":{
"calls":"https://api.surevoip.co.uk/calls",
"sms":"https://api.surevoip.co.uk/sms",
"numbers":"https://api.surevoip.co.uk/numbers",
"contact":"https://api.surevoip.co.uk/contact",
"sip":"https://api.surevoip.co.uk/sip",
"partners":"https://api.surevoip.co.uk/partners",
"faxes":"https://api.surevoip.co.uk/faxes",
"areacodes":"https://api.surevoip.co.uk/numbers/areacodes",
"service-status":"https://api.surevoip.co.uk/support/service-status",
"porting":"https://api.surevoip.co.uk/porting",
"customers":"https://api.surevoip.co.uk/customers",
"ip-address":"https://api.surevoip.co.uk/support/ip-address",
"echo":"https://api.surevoip.co.uk/support/echo",
"billing":"https://api.surevoip.co.uk/billing"
},
"location":"https://api.surevoip.co.uk/customers/{account}",
"customer_resources":{
"urls":[
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls",
"title":"calls"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls/stats",
"title":"call stats"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/billing/invoices",
"title":"billing invoices"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/billing/contact",
"title":"billing contact details"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/999-address",
"title":"999 address"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/support/",
"title":"support tickets"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers",
"title":"numbers"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/countries/",
"title":"numbers by country"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/states/",
"title":"numbers by states"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/cities/",
"title":"numbers by city"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/areacodes/",
"title":"numbers by areacode"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/faxes",
"title":"faxes"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/sms",
"title":"sms"
},
{
"href":"https://api.surevoip.co.uk/contact",
"title":"contact"
},
{
"href":"https://api.surevoip.co.uk/support/ip-address",
"title":"ip-address"
},
{
"href":"https://api.surevoip.co.uk/support/echo",
"title":"echo"
},
{
"href":"https://api.surevoip.co.uk/support",
"title":"numbers"
},
{
"href":"https://api.surevoip.co.uk/numbers/countries/",
"title":"numbers by country"
},
{
"href":"https://api.surevoip.co.uk/numbers/states/",
"title":"numbers by states"
},
{
"href":"https://api.surevoip.co.uk/numbers/cities/",
"title":"numbers by city"
},
{
"href":"https://api.surevoip.co.uk/numbers/areacodes/",
"title":"numbers by areacode"
},
{
"href":"https://api.surevoip.co.uk/support/service-status",
"title":"service-status"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/sip",
"title":"sip"
}
]
}
}
You can then use that **Location header** to GET your account details:
curl -i -X GET -u username:password https://api.surevoip.co.uk/customers/{account}
which returns:
HTTP/1.1 200 OK
Server: nginx/1.0.14
Date: Fri, 18 Jan 2017 10:43:25 GMT
Content-Type: application/json
Connection: keep-alive
Vary: Content-Type
Content-Length: 3117
X-Catalyst: 5.90011
X-SureVoIP-API-Auth-User: XXX
X-SureVoIP-API-Version: 3.50
{
"resources":{
"calls":"https://api.surevoip.co.uk/calls",
"sms":"https://api.surevoip.co.uk/sms",
"numbers":"https://api.surevoip.co.uk/numbers",
"contact":"https://api.surevoip.co.uk/contact",
"sip":"https://api.surevoip.co.uk/sip",
"partners":"https://api.surevoip.co.uk/partners",
"faxes":"https://api.surevoip.co.uk/faxes",
"areacodes":"https://api.surevoip.co.uk/numbers/areacodes",
"service-status":"https://api.surevoip.co.uk/support/service-status",
"porting":"https://api.surevoip.co.uk/porting",
"customers":"https://api.surevoip.co.uk/customers",
"ip-address":"https://api.surevoip.co.uk/support/ip-address",
"echo":"https://api.surevoip.co.uk/support/echo",
"billing":"https://api.surevoip.co.uk/billing"
},
"firstname":"Gavin",
"company_name":"Suretec Systems Ltd.",
"lastname":"Henry",
"state":"Aberdeenshire",
"email":"user@example.com",
"city":"Inverurie",
"fax":"",
"address":"24 Cormack Park, Rothienorman",
"company_website":"www.example.com",
"postcode":"AB51 8GL",
"country":"GBR",
"phone":"01224 279484",
"username":"XXX",
"balance":"786666.53852",
"creditlimit":"100000",
"customer_resources":{
"urls":[
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls",
"title":"calls"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/calls/stats",
"title":"call stats"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/billing/invoices",
"title":"billing invoices"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/billing/contact",
"title":"billing contact details"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/999-address",
"title":"999 address"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/support/",
"title":"support tickets"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers",
"title":"numbers"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/countries/",
"title":"numbers by country"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/states/",
"title":"numbers by states"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/cities/",
"title":"numbers by city"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/numbers/areacodes/",
"title":"numbers by areacode"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/faxes",
"title":"faxes"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/sms",
"title":"sms"
},
{
"href":"https://api.surevoip.co.uk/contact",
"title":"contact"
},
{
"href":"https://api.surevoip.co.uk/support/ip-address",
"title":"ip-address"
},
{
"href":"https://api.surevoip.co.uk/support/echo",
"title":"echo"
},
{
"href":"https://api.surevoip.co.uk/support",
"title":"numbers"
},
{
"href":"https://api.surevoip.co.uk/numbers/countries/",
"title":"numbers by country"
},
{
"href":"https://api.surevoip.co.uk/numbers/states/",
"title":"numbers by states"
},
{
"href":"https://api.surevoip.co.uk/numbers/cities/",
"title":"numbers by city"
},
{
"href":"https://api.surevoip.co.uk/numbers/areacodes/",
"title":"numbers by areacode"
},
{
"href":"https://api.surevoip.co.uk/support/service-status",
"title":"service-status"
},
{
"href":"https://api.surevoip.co.uk/customers/{account}/sip",
"title":"sip"
}
]
}
}
You can POST to the top level customer resource if you are a partner or SureVoIP admin. This will create a new customer resource under your account whereby we return a **201 Created** with the **location** header populated:
https://api.surevoip.co.uk/partners/{partner_name}/customer/{new_customer_lives_here}
==== Create ====
curl -i -X POST -u username:password https://api.surevoip.co.uk/customers -H 'Content-Type: application/json' -T new_customer.json
using: