[% IF uri -%] [% END -%] [% title %] [% IF uri -%] [% END -%]

This documentation describes the Sipwise NGCP HTTP API, which is used to control the NGCP platform via 3rd party applications. It is also a machine-readable service document and serves as entry point for API clients.

The Sipwise NGCP HTTP API strictly follows the REST principle and uses the JSON Hypertext Application Language (JSON-HAL) to express resources and their relations. This means, compared to typical plain JSON APIs, that relations between resources are defined as hyperlinks within the JSON objects, so a client can and should navigate between related objects without hard-coding any URIs.

Brief Overview of JSON-HAL HAL is a generic media type with which Web APIs can be developed and exposed as series of links. Clients of these APIs can select links by their link relation type and traverse them in order to progress through the application. A HAL document uses the format described in RFC4627 - The application/json Media Type for JavaScript Object Notation (JSON) and has the media type application/hal+json. An example request to fetch a customercontacts item with id 1 via the API looks like this: GET /api/customercontacts/1 HTTP/1.1 Accept: application/hal+json The corresponding response is as follows: HTTP/1.1 200 OK Content-Type: application/hal+json { "_links": { "self": { "href": "/api/customercontacts/1" }, "ngcp:reseller": { "href": "/api/resellers/5" }, }, "firstname": "John", "lastname": "Doe", "email": "john.doe@example.org" } Here, we have a HAL document representing a contact resource with the URI /api/customercontacts/1. It has a link to a reseller it belongs to, and its own state in the form of firstname, lastname and email properties. To fetch the reseller of this contact, an API client only has to follow the link provided in _links.reseller.href. A simple code example might look like this: $ua = LWP::UserAgent->new; # fetch the contact (URI hardcoded for simplicity only!) $contact = from_json($ua->get('https://example.org/api/customercontacts/1')); # follow the reseller link to fetch the reseller of this contact $reseller = from_json($ua->get($contact->{'_links'}->{'ngcp:reseller'}->{'href'}); API Versioning Due to the JSON-HAL structure, all related resources are hyperlinked, which implies that no strict API versioning is required. If URIs change between NGCP versions, the hyperlinks in the JSON-HAL documents are updated accordingly. As a consequence, this means that a client implemented against the API should not hardcode URIs, rather than using the hyperlinks provided in the resources. Query Parameters Some collections define query parameters to filter the output. Typical use cases are limiting collections to a specific reseller or a specific customer. Query parameters are appended to the URL like in the following example: curl -X GET 'https://example.org:1443/api/somecollection/?param_one=1&param2=something' Some query parameters allow wildcard/pattern matching, which is expressed by a '*' like this: curl -X GET 'https://example.org:1443/api/somecollection/?param=*something*' Note: this examples do not yet contain authentication and will therefore not work on a standard installation. To read more about that go to the Chapter Authentication. HTTP Response Codes The REST API returns an HTTP response code with the following classes: 1xx Provisional Responses The server sends the following provisional responses, and the user agent on the client is expected to handle it transparently without any special handling in the code using the API: 2xx Successful Responses The server sends the following successful responses: 3xx Redirection Responses The server redirects the clients using the following return codes: 4xx Client Error The server rejects a client request with the following response codes: 5xx Server Error The server sends the following error codes in case of internal issues: [% # vim: set tabstop=4 syntax=html expandtab: -%]