Access Resources
In order to access a private project's resources over the API, you must include a valid access token in the Authorization header with each request:
Authorization: Bearer {access_token}
For example, using jQuery: (Open in browser)
1
//Example of getting entries using jQuery
2
3
//Replace parameters with your own
4
var params = {
5
grant_type: 'client_credentials',
6
client_id: 2,
7
client_secret: 'QowjYIFrWbzLEwttXzuTnb20OPbRWwlPlaNLQ6VW'
8
}
9
10
//perform Ajax request to get token
11
$.ajax({
12
url: 'https://five.epicollect.net/api/oauth/token',
13
type: 'POST',
14
contentType: 'application/vnd.api+json',
15
data: JSON.stringify(params),
16
success: function(response) {
17
console.log(JSON.stringify(response));
18
//the token is valid for 2 hours, let's get the entries
19
_getEntries(response.access_token);
20
},
21
error: function(xhr, status, error) {
22
console.log(xhr.responseText);
23
}
24
});
25
26
//get the entries, passing token for authorisation
27
//ec5-api-test is the project slug
28
function _getEntries(token) {
29
$.ajax({
30
url: 'https://five.epicollect.net/api/export/entries/ec5-api-test',
31
type: 'GET',
32
contentType: 'application/vnd.api+json',
33
headers: {
34
Authorization: 'Bearer ' + token
35
},
36
success: function(response) {
37
//Here are the entries, just log them for now ;)
38
console.log(JSON.stringify(response));
39
40
//do what you want with the response (entries)
41
// ...
42
},
43
error: function(xhr, status, error) {
44
console.log(xhr.responseText);
45
}
46
});
47
}
Copied!
Using PHP, with Guzzle: (Add your project credentials accordingly)
1
use GuzzleHttp\Exception\RequestException;
2
use GuzzleHttp\Client;
3
4
$tokenClient = new Client(); //GuzzleHttp\Client
5
$tokenURL = 'https://five.epicollect.net/api/oauth/token';
6
7
//get token first
8
try {
9
$tokenResponse = $tokenClient->request('POST', $tokenURL, [
10
'headers' => ['Content-Type' => 'application/vnd.api+json'],
11
'body' => json_encode([
12
'grant_type' => 'client_credentials',
13
'client_id' => {your_client_id},
14
'client_secret' => '{your_client_secret}'
15
])
16
]);
17
18
$body = $tokenResponse->getBody();
19
$obj = json_decode($body);
20
$token = $obj->access_token;
21
} catch (RequestException $e) {
22
//handle errors
23
//...
24
}
25
26
//get entries now
27
$entriesURL = 'https://five.epicollect.net/api/export/entries/{project_slug}';
28
$entriesClient = new Client([
29
'headers' => [
30
'Authorization' => 'Bearer '.$token //this will last for 2 hours!
31
]
32
]);
33
34
try {
35
$response = $entriesClient-> request('GET', $entriesURL);
36
37
$body = $response->getBody();
38
$obj = json_decode($body);
39
40
//do something with the entries
41
echo '<pre>';
42
print_r($obj);
43
echo '</pre>';
44
45
} catch (RequestException $e) {
46
//handle errors
47
//...
48
}
Copied!
Please note the entries are paginated by 50 at a time.
Last modified 2yr ago
Copy link