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>
Babel + JSX
//Example of getting entries using jQuery
//Replace parameters with your own credentials
var params = {
grant_type: 'client_credentials',
client_id: 153,
client_secret: 'J7SZDPssR885Fo0xczGKqkJfa5XyMK8wxbrOYjio'
}
//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);
}
}); */
async function _getToken(){
const res = await axios.post('https://five.epicollect.net/api/oauth/token', { params: { answer: 42 } });
}
_getToken();
//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));
}
});
}