# 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.


:::tip
The latest OpenAPI documentation can be found here:  
[__https://openapi.drive.cybersift.io/__](https://openapi.drive.cybersift.io/) 

:::

## Testing Deployment

### Testing if an API key is valid

```bash
curl -s --header "X-Drive-Token: token_here"  http://localhost:8081/app/retrieveAppSettings
```

A 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

```bash
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

```bash
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”.


:::info
**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

```bash
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:

```bash
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:


```javascript
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**.


```bash
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:

```bash
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 GMT
```



:::info
In 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:


```bash
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:


```bash
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. 


 ![](https://outline.cybersift.io/api/files.get?sig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1cGxvYWRzL2MwNWNhZDYzLTA0ZmEtNGFmZC04NjMwLTI3MjNjZDYwZWZkNS9lMTg3NzQwNy1jNTU0LTQzNTItOTY2NS1mMDhjNmQ0MWVjN2YvRzJqUFd5dmI0bHUxbzRDSnVBcnBxVVpaeDVmblpvb1pXUjUyM21uT21vN0VSMEVOc3g3ZjNPamRrV0JrczVWa3NBOFlqMFRhcTVpalN6ZDlCTDBpWlltN1ROSWZrSklwWlZjNmNDa3l2bm14MmVSY1J6Z094cnJ3SjIxM2lsQlpVUUpZN3BGQ0VseUpEQ3VNU3BLdmxEZyIsInR5cGUiOiJhdHRhY2htZW50IiwiaWF0IjoxNzk1NDQ4NzAwLCJleHAiOjE3OTU1MzUxMDB9.h2-nYpNXcY5ltbs-QGnBJQfOijMogQ6R0S6bLm1AA0c " =477x674")



* 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”



---


:::info
tags:

* Developer settings
* OpenAPI

:::

---

**Documents**

- [1.0 Getting Started](https://outline.cybersift.io/s/cs-drive/doc/10-getting-started-uRQNa8gyos)
- [2.0 Updating](https://outline.cybersift.io/s/cs-drive/doc/20-updating-MLRKSOfzo0)
- [3.0 Development](https://outline.cybersift.io/s/cs-drive/doc/30-development-UcOt6ecH7O)
- [FAQ](https://outline.cybersift.io/s/cs-drive/doc/faq-Qu4pHGbI2B)