Requesting, headers and encoding (and version)
Most endpoints support both GET and POST. Parameters may be
passed as query-string parameters, as form-encoded POST data, or as a
JSON body (with Content-Type: application/json); the three forms are
equivalent, and a few endpoints whose parameters are lists — this is
then documented — require the JSON body form.
You may specify the encoding the API should use to return data through standard HTTP content negotiation.
The header to use is "Accept" and must contain a version information.
Accept: application/json;version=0
(version must be present, but is usually reserved for the future, therefore, some endpoints like SMS functions require another value, in that case, this is documented)
Available encoders are:
| Encoding | Comment |
|---|---|
| JSON | Available |
| XML | Available |
| YAML | partially implemented, nested dictionaries can have issues |
| TEXT | partially implemented, nested dictionaries can have issues |
| HTML | not always available, exists for user comfort, but not really usable as an API |
The reply envelope
Whatever the encoding, successful replies share a common envelope: the
endpoint-specific data is accompanied by a few common fields —
code (the HTTP status, repeated in the body), diagnostic (a short
human-readable outcome, "Success" on success), stamp (the server
time of the reply), url (the requested URL) and version (the API
version used to answer). Errors use the same envelope, with the
appropriate code and a diagnostic explaining what went wrong.
Here is an example of a query with good headers:
% curl -H 'Accept: application/json;version=0' 'https://api.ubity.com/call?key=KKKK&exten=EEE&number=NNN'
{
"api_call_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"api_key": "KKKK",
"code": 200,
"diagnostic": "Success",
"mode": "normal",
"stamp": "2018-02-06 10:10",
"url": "https://api.ubity.com/call?key=KKKK&exten=EEE&number=NNN",
"version": 0
}
-
For historical reasons and compatibility concerns, some endpoints do not have a consistent encoding when used without specifying headers. This is called the legacy behaviour, it's not supported nor documented, please don't use it (anymore) as it can be removed at any moment. So, it's strongly recommended to always request using the headers (encoding and version). ↩