EC5 Api Test localhost

by ParanoidAndroid77

HTML

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

JavaScript

var params = {
   grant_type: 'client_credentials',
   client_id: 5,
   client_secret: 'caVwUdoA7GMXHcaQXn8uR5MzOQKCvSmpZpurCbZ2'
 }
 
 var entriesUrls = [
 'https://fddc1843.ngrok.io/~mirko/epicollect5-server/public/api/export/entries/bestpint',//mapped entries
 'https://fddc1843.ngrok.io/~mirko/epicollect5-server/public/api/entries/bestpint',//raw entries
 'https://fddc1843.ngrok.io/~mirko/epicollect5-server/public/api/entries-locations/bestpint'//raw entries location
 ];
 

 $.ajax({
   url: 'https://fddc1843.ngrok.io/~mirko/epicollect5-server/public/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
     
     entriesUrls.forEach(function(url){
      _getEntries(response.access_token, url);
     });
   },
   error: function(xhr, status, error) {
     console.log(xhr.responseText);
   }
 });

 function _getEntries(token, url) {
   $.ajax({
     url: url,
     type: 'GET',
     contentType: 'application/vnd.api+json',
    headers: {
       Authorization: 'Bearer ' + token
     },
     success: function(response) {
       console.log(JSON.stringify(response));
     },
     error: function(xhr, status, error) {
       console.log(xhr.responseText);
     }
   });
 }