If you need additional information on an archive, such as which index fields exist, you can query this with the GET route /application/users/:username/archives/:archive. The archive is identified through the database table name or the GUID (parameter :archive). The call is made in a user context. Only users with access to the archive can read these information. The user is identified through the username (parameter :username). The return value has the following JSON format:
{
"users": {
"archives": [
{
"name": "Invoices",
... further archive properties ...
"indexFieldDefinitions": [
{
"name": "deadline",
... further index field properties ...
},
... further index fields ...
]
}
]
}
}
Example: Determine required fields
guzzlehttp
// User has been authenticated already
try {
$response = $client->request(
'GET',
'application/users/jdoe/archives/invoices'
);
$responseBody = json_decode($response->getBody(), true);
$archiveDetails = $body['users']['archives'][0];
$requiredFields = [];
foreach ($archiveDetails['indexFieldDefinitions'] as $fieldDefinition) {
if ($fieldDefinition['required']) {
array_push($requiredFields, $fieldDefinition['name']);
}
}
echo "Required fields: " . implode(',', $requiredFields) . "\n";
} catch (Exception $e) {
echo "Error during performance: " . $e->getMessage() . "\n";
}
//
cURL
// User has been authenticated already
curl_setopt($curlHandle, CURLOPT_URL,
'http://example.org/jobrouter/api/rest/v2/application/users/jdoe/archives/invoices');
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curlHandle, CURLOPT_COOKIEFILE, 'path/to/cooke/file.cookie');
$response = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
curl_close();
if ($statusCode == 200) {
$decodedResponse = json_decode($response, true);
$archiveDetails = $response['users']['archives'][0];
$requiredFields = [];
foreach ($archiveDetails['indexFieldDefinitions'] as $fieldDefinition){
if ($fieldDefinition['required']) {
array_push($requiredFields, $fieldDefinition['name']);
}
}
echo "Required fields: " . implode(',', $requiredFields) . "\n";
} else {
echo "Error during performance: Code - " . $statusCode . ", ";
echo "Response: " . var_export($response, true);
}
//