3.2 OpenAPI
Authentication
All the API calls to the server must include a header named “X-Drive-Token: abc123”, which is obtained from sysadmins.
The latest OpenAPI documentation can be found here:
https://openapi.drive.cybersift.io/
Testing Deployment
Testing if an API key is valid
curl -s --header "X-Drive-Token: token_here" http://localhost:8081/app/retrieveAppSettingsA bad or expired token will return an HTTP 401 with “NOK” as a body. If the token is valid it will return a JSON body with the app profile configuration as set by the sysadmins.
Uploading a file - sysadmin intervention required
curl -X POST http://localhost:8081/app/upload -H "X-Drive-Token: token_here" -H "Content-Type: multipart/form-data" -F files[]=@report.pdf
[{"FileID":"35fe2a91-3b6d-45ce-b94b-74b2e19f70be","Filename":"report.pdf","DetectedExtension":"","AllowedByPolicy":false,"Verdict":"No file sink bound to this policy - contact support"}]
In the above sample request, an HTTP status of 512 is returned, along with a JSON response containing the “verdict” field which gives a reason for the failure. Please communicate this with sysadmins should this response be returned.
Uploading a single file - success
curl -X POST http://localhost:8081/app/upload -H "X-Drive-Token: token_here" -H "Content-Type: multipart/form-data" -F files[]=@report.pdf
[{"FileID":"29598eec-9d13-4983-b130-2d065bbb4753","Filename":"report.pdf","DetectedExtension":"pdf","AllowedByPolicy":true,"Verdict":"Success"}]In the above sample, note the file being uploaded via form-data, and the response being a JSON array containing a single object corresponding to the uploaded file, with the “Verdict” field set to “success”.
NB: In this case the call was synchronous since the policy bound to this API key did not involve heavy checks. However in some cases (see examples below) this may not be the case and checks are performed asynchronously
Uploading multiple files - malware detected in one
curl -X POST http://localhost:8081/app/upload -H "X-Drive-Token: token_here" -H "Content-Type: multipart/form-data" -F files[]=@report.pdf -F files[]=@vorm_a_ee_en_2022.pdf
[
{"FileID":"13188e30-3291-4b9b-a2cb-6f84b69a9bd0","Filename":"report.pdf","DetectedExtension":"pdf","AllowedByPolicy":true,"Verdict":"Success"},
{"FileID":"a7a193f6-9492-4e6a-a7c2-1959dc9f184f","Filename":"vorm_a_ee_en_2022.pdf","DetectedExtension":"pdf","AllowedByPolicy":false,"Verdict":"Antivirus detected malware - Quarantined"}
]In the above sample, note that two files are being uploaded via form-data, and the response being a JSON array containing two objects corresponding to the uploaded files, with one “Verdict” field set to “success”, while the other set to an “antivirus detected malware” result
Uploading file async - heavy checks enabled
Depending on the profile setup by sysadmins, “heavy” checks on uploaded documents may be enabled (such as sanitizing PDFs or content disarming on office documents). In such cases, uploads are placed in a background queue for processing.
The below sample shows such a situation:
curl -X POST http://localhost:8081/app/upload -H "X-Drive-Token: token_here" -H "Content-Type: multipart/form-data" -F files[]=@'client balance.pdf'
[{"FileID":"5d37d661-b2da-4231-b441-02288d76ccf5","Filename":"client balance.pdf","DetectedExtension":"pdf","AllowedByPolicy":true,"Verdict":"Disarming"}]In the above example, note how the “Verdict” field is set to “disarming”, rather than success/quarantined as before. In this case, the FileID must be noted and checked for status in subsequent API calls to the /app/retrieveFileStatus endpoint.
For example:
curl -X POST http://localhost:8081/app/retrieveFileStatus -H "X-Drive-Token: token_here" -H "Content-Type: application/json" --data '{"FileID":"5d37d661-b2da-4231-b441-02288d76ccf5"}'
{"ID":15,"Timestamp":1678883051,"@timestamp":0,"FileID":"5d37d661-b2da-4231-b441-02288d76ccf5","Uploader":"api-demo-key","UserEmail":"","ProfileName":"api-pdf-only","Destination":"","FileSinkID":1678793272,"FileSink":{"ID":0,"FriendlyName":"","Path":"","Type":"","Profiles":null},"Filename":"client balance.pdf","Status":"Success"}
In the above request/response note that we queried the “retrieveFileStatus” endpoint to check if a file was successfully processed in the background.
Downloading files - a sample flow
Step 1
Get an initial list of files available to download. To do this query the retrieveProfileFiles endpoint, with SinceID set to 0.
curl -X POST http://localhost:8081/app/retrieveProfileFiles -H "X-Drive-Token: token_here" -H "Content-Type: application/json" --data '{"SinceID":0}'
[
{
"ID":8,
"Timestamp":1678793426,
"@timestamp":0,
"FileID":"13188e30-3291-4b9b-a2cb-6f84b69a9bd0",
"Uploader":"api-demo-key",
"UserEmail":"",
"ProfileName":"api-pdf-only",
"Destination":"",
"FileSinkID":1678793272,
"FileSink":{
"ID":0,
"FriendlyName":"",
"Path":"",
"Type":"",
"Profiles":null
},
"Filename":"report.pdf",
"Status":"Success"
},
// items removed for clarity…
{
"ID":12,
"Timestamp":1678883051,
"@timestamp":0,
"FileID":"203897c8-c2a1-4070-8345-cbe82ab3cccf",
"Uploader":"api-demo-key",
"UserEmail":"",
"ProfileName":"api-pdf-only",
"Destination":"",
"FileSinkID":1678793272,
"FileSink":{
"ID":0,
"FriendlyName":"",
"Path":"",
"Type":"",
"Profiles":null
},
"Filename":"client balance.pdf",
"Status":"Success"
}
]
Step 2
For each file returned, call the retrieveFile endpoint with the ID field set to what was returned in the previous step.
Example 1:
curl -vvv -X POST http://localhost:8081/app/retrieveFile -H "X-Drive-Token: token_here" -H "Content-Type: application/json" --data '{"id":8}'
> POST /app/retrieveFile HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.81.0
> Accept: */*
> X-Drive-Token: token_here
> Content-Type: application/json
> Content-Length: 8
>
< HTTP/1.1 204 No Content
< Content-Type: application/json; charset=utf-8
< Date: Thu, 16 Mar 2023 10:01:01 GMTIn the above example, note that an http code of 204 (No Content) was returned. This means that the file has been deleted or moved on the file server and this ID exists only for logging/auditing purposes.
Example 2:
curl -vvv -X POST http://localhost:8081/app/retrieveFile -H "X-Drive-Token: token_here" -H "Content-Type: application/json" --data '{"id":12}' --output test.pdf
> POST /app/retrieveFile HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.81.0
> Accept: */*
> X-Drive-Token: token_here
> Content-Type: application/json
> Content-Length: 9
>
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 35197
< Content-Type: application/pdf
< Last-Modified: Wed, 15 Mar 2023 12:24:14 GMT
< Date: Thu, 16 Mar 2023 10:04:17 GMT
<
[26446 bytes data]
In the above example, the file was saved successfully since an HTTP 200 OK was returned. PS: note the use of the --output switch in the curl command above
Step 3
After each file download, store the last file ID downloaded in your application state for later use.
Step 4
Periodically poll the server for new files available to download, by performing steps 1 to 3 again. The only difference should be that in step 1, set the sinceID field to the last file ID stored in step 3, example:
curl -X POST http://localhost:8081/app/retrieveProfileFiles -H "X-Drive-Token: token_here" -H "Content-Type: application/json" --data '{"SinceID":12}'
[]Important Notes
Downloading files
When calling the retrieveProfileFiles endpoint, note a couple of points.
The “Id” field is NOT guaranteed to be incremental. Please do not assume a future or past value for the “Id” field
Ensure that the “Status” field is set to “Success”, otherwise you may not be downloading a clean file. Unless this is the intention of course… your use case may be writing an app which analyses the files which are detected as being “malicious”
tags:
Developer settings
OpenAPI