If you want to store a document in a JobRouter archive, use the POST route /application/jobarchive/archives/:archive/documents. With the archive parameter you specify the archive (archive GUID or archive table). Files and index data are transferred in the HTTP request body:
•Array files – Contains the document files
•Array indexFields – Contains index data
•Array keywordFields – Contains keywords
The index data are built as follows:
•indexFields[<Index>][name] – Contains the index name (as defined in the archive configuration)
•indexFields[<Index>][value] – Contains the index values
The same index identifies a name/value pair. The keywords follow the same pattern, though it is possible to assign several values to one keyword (separated by a comma under the key keywords).
Examples for index data
indexFields[0][name] = 'document_type'
indexFields[0][value] = 'invoice'
keywordFields[0][name] = 'tag'
keywordFields[0][keywords] = 'finance,accounting'
Please note: Only users with an archive profile can store documents in the archive.
Response
The response is in JSON format and contains the ID of the archived documents, as well as the URLs for the download of the main file, the attachments and all document files:
{
"archivedocumentrevisions": [
{
"revisionId": 12345
}
],
"meta": {
"locations": [
"...\/0E4C6620-B576-D6A0-F919-61B3F2EEBA78\/documents\/12345\/file",
"...\/0E4C6620-B576-D6A0-F919-61B3F2EEBA78\/documents\/12345\/files",
"...\/0E4C6620-B576-D6A0-F919-61B3F2EEBA78\/documents\/12345\/clippedfiles"
]
}
}
Example: Archive document with two files and index data
guzzlehttp
// User has been authenticated already
// Define files and index data
$documentContentAndMetaData = [
[
'name' => 'indexFields[0][name]',
'contents' => 'title_field',
],
[
'name' => 'indexFields[0][value]',
'contents' => 'My REST example with guzzlehttp',
],
[
'name' => 'indexFields[1][name]',
'contents' => 'number_field',
],
[
'name' => 'indexFields[1][value]',
'contents' => '123',
],
[
'name' => 'indexFields[2][name]',
'contents' => 'date_field',
],
[
'name' => 'indexFields[2][value]',
'contents' => '2018-09-21T11:20:40+01:00',
],
[
'name' => 'keywordFields[0][name]',
'contents' => 'tags_field',
],
[
'name' => 'keywordFields[0][keywords]',
'contents' => 'REST',
],
[
'name' => 'files[0]',
'contents' => fopen('/path/to/my/rest/file.pdf', 'r'),
],
[
'name' => 'files[1]',
'contents' => fopen('/path/to/my/rest/note.txt', 'r'),
],
];
try {
$response = $client->request(
'POST',
'application/jobarchive/archives/invoices/documents',
[
'multipart' => $documentContentAndMetaData,
]
);
if ($response->getStatusCode() == 201) {
$body = json_decode($response->getBody(), true);
echo "Dokument-ID: ";
echo $body['archivedocumentrevisions'][0]['revisionId'] . "\n";
}
} catch (Exception $e) {
echo "Error during performance: " . $e->getMessage() . "\n";
}
cURL
// User has been authenticated already
// Define files and index data
$mainFile = new CURLFile('/path/to/invoice/file.pdf');
$clippedFile = new CURLFile('/path/to/invoice/note.txt');
$documentContentAndMetaData = [
'indexFields[0][name]' => 'title_field',
'indexFields[0][value]' => 'My REST example with cURL',
'indexFields[1][name]' => 'number_field',
'indexFields[1][value]' => 321,
'indexFields[2][name]' => 'date_field',
'indexFields[2][value]' => '2018-09-21T11:20:40+01:00',
'keywordFields[0][name]' => 'tags_field',
'keywordFields[0][keywords]' => 'REST',
'files[0]' => $mainFile,
'files[1] => $clippedFile
];
curl_setopt($curlHandle, CURLOPT_URL,
'http://example.org/jobrouter/api/rest/v2/application/' .
'jobarchive/archives/invoices/documents');
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $documentContentAndMetaData);
curl_setopt($curlHandle, CURLOPT_COOKIEFILE, 'path/to/cookie/file.cookie');
$response = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
curl_close();
if ($statusCode == 200) {
$documentData = json_decode($response, true);
echo "Dokument-ID: ";
echo $documentData['archivedocumentrevisions'][0]['revisionId'] . "\n";
} else {
echo "Error during performance: Code - " . $statusCode . ", ";
echo "Response: " . var_export($response, true);
}