EC5 API (Private)

Testing EC5 API

by ParanoidAndroid77

HTML

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<pre class="content"></pre>

JavaScript

//Example of getting entries using jQuery

//Replace parameters with your own credentials
var params = {
  grant_type: 'client_credentials',
  client_id: 4879,
  client_secret: 'XbIHCZHh5WQhJCaLduHSAzzddFFI6PkHA78XUZeE'
}
//replace with your project slug
var projectSlug = "ec5-api-private";

//perform jax request to get token
$.ajax({
  url: 'https://five.epicollect.net/api/oauth/token',
  type: 'POST',
  contentType: 'application/vnd.api+json',
  data: JSON.stringify(params),
  success: function(response) {
    console.log(JSON.stringify(response));
    //the token is valid for 2 hours, let's get the entries
    _getEntries(response.access_token);
  },
  error: function(xhr, status, error) {
    console.log(xhr.responseText);
  }
});

//get the entries, passing token for authorisation
function _getEntries(token) {
  $.ajax({
    url: 'https://five.epicollect.net/api/export/entries/' + projectSlug,
    type: 'GET',
    contentType: 'application/vnd.api+json',
    headers: {
      Authorization: 'Bearer ' + token
    },
    success: function(response) {
      //console.log(JSON.stringify(response));
      $('.content').text(JSON.stringify(response, null, 2));
    },
    error: function(xhr, status, error) {
      $('.content').text(JSON.stringify(response, null, 2));
    }
  });
}