icon_qa

INTRODUZIONE API REST

HANDLE RESPONSE

Response Codes (HTTP Status Code)

or each request, the REST APIs return one of the following HTTP Status Code :

200 - Request completed successfully

204 - Request completed successfully: resorce deleted

400 - Missing parameter

401 - Authentication failed

404 - Resource not found

405 - HTTP method not allowed

500 - An unexpected error occurred in the server

Response content

For each call HTTP GET and HTTP POST completed successfully (HTTP status 200 ) REST API returns the content as a JSON / XML

In the case of HTTP PUT and HTTP DELETE completed successfully (HTTP status 200 or 204 ) the content of the answer is empty.

If a call terminate with an error (HTTP status other than 200 or 204 ) a JSON / XML response containing error explanation:

errorCode - HTTP status code

errorMsg - smsHosting.it code to identify the problem type/p>

Ad esempio nel caso l'autenticazione fallisca le REST API restituiscono un HTTP Status 401 e come contenuto:

For example in the case of authentication failure the REST APIs return HTTP Status 401 and as content :

{
   "errorMsg":"BAD_CREDENTIALS",
   "errorCode":401
}

Pagination

Some resources ( search text messages sent or received , search contacts, etc.) returns result as pages .

For example, the search text messages sent return the following JSON

{
   "metadata":{
      "count":1,
      "offset":0,
      "limit":20
   },
   "smsList":[
      {
         "id":389395385,
         "to":"393480000000",
         "text":"Test Sms",
         "from":"mrossi",
         "status":"DELIVERED",
         "insertDate":"2014-01-13T15:01:35+0100",
         "sentDate":"2014-01-13T15:01:37+0100",
         "deliveryDate":"2014-01-13T15:01:40+0100",
         "transactionId":"72810108d4114097b9edb42b255b273c",
         "price":0.0945
      }
   ]
}

The field metadatacontains the informations useful to managing the results pagetion.

The property count indicates the total number of results found for that search.

Fields offset and limit denote the index of the first result and the number of results returned

offset and limit can be used as parameters in the request in order to control the range of results returned.

For example, if a search retrive 100 results and the page size is 20

{
   "metadata":{
      "count":100,
      "offset":0,
      "limit":20
   },
   .......
}

you can get 5 pages using the following values ​​of offset and limit:

page 1 - offset=0&limit=20
page 2 - offset=20&limit=20
page 3 - offset=40&limit=20
page 4 - offset=60&limit=20
page 5 - offset=80&limit=20