Response formats

Introduction

The REST API can respond to the requests in different formats. By default, it returns a response in JSON format but it can also return a response in XML, CSV (for certain resources) and JS (JSONP) formats.

To change the format, .xml, .json, .csv or .js must be added to the end of the URI regardless of the HTTP verb (GET, POST, DELETE or PUT).

Examples

To retrieve the list of mailings in JSON format

GET /rest/resource.json HTTP/1.1

Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6ImYyMzE2…
Host: api.messengeo.net
Content-Type: application/x-www-form-urlencoded

To retrieve the list of mailings in XML format

GET /rest/resource.xml HTTP/1.1

Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6ImYyMzE2…
Host: api.messengeo.net
Content-Type: application/x-www-form-urlencoded

To retrieve the list of mailings in CSV format

GET /rest/resource.csv HTTP/1.1

Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6ImYyMzE2…
Host: api.messengeo.net
Content-Type: application/x-www-form-urlencoded

To retrieve the list of mailings in JSONP format

GET /rest/resource.js HTTP/1.1

Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpZCI6ImYyMzE2…
Host: api.messengeo.net
Content-Type: application/x-www-form-urlencoded

 

callback=yourFunctionCallback

Cross-domain

Retrieving the response in javascript format allows you to overcome the difficulties linked to the cross-domain. Passing through a server in order to consult the API's directly is thus avoided. On the client side, it is recommended to use the jquery-jsonp plugin (jQuery-jsonp on GitHub) for error management (not initially available in JQuery).

For example, reading the resource of which the id is 2 via an ajax request returns

<script type="text/javascript" language="javascript" src="jquery.jsonp.js"></script>
<script>
$.jsonp({
      url: 'https://api.messengeo.net/rest/resource.js?callback=?',
      beforeSend: function (request) {
          request.setRequestHeader("Authorization", "Bearer " + ($("#accesstoken").val()));
      },
      data: {
          id: '2',
      }
  }).done(function(data) {
     // data peut être un objectlist (size, total, list) ou une erreur (status, message)
     console.log(data);
  }).fail(function(jqxhr, textStatus, errorThrown) {
     console.log('Errors occured');
  });
</script>