Skip to main content

My Files and Shared Folders REST Interface

A 'My Files and Shared Folders' REST interface is available and can be accessed via https://<host>/env/<script>/rest/folders where <host> is the hostname of the Coins server and <script> is the environment. You will see these values used in the normal Coins ERP+ URL and might be something like https://mycompany.coinscloud.com/env/live/rest/folders

The following endpoints are available:

Method

Relative Path

Description

GET

/rest/folders/{folder}

Get details of a folder

GET

/rest/folders/{folder}/files

Get a list of files in a folder

GET

/rest/folders/{folder}/files/{file}

Get details of a file

POST

/rest/folders/{folder}/files/{file}

Create a new file in a folder

PUT

/rest/folders/{folder}/files/{file}

Create or update a file in a folder

DELETE

/rest/folders/{folder}/files/{file}

Delete a file in a folder

GET

/rest/folders/{folder}/files/{file}/download

Download the file

The “{folder}” value in the URL can be either the User ID (My Files) or a shared folder (both in lower case). If the folder exists in $BASE/var/home then the details and files can be manipulated.

The “{file}” value in the URL is the file name of the file in the folder.


The following request was made using POSTMAN:

GET /env/dev/rest/folders

Accept: application/json

cache-control: no-cache

Postman-Token: 9ea20a12-3cc9-48d9-b328-d9d8289cc3d6

Authorization: Basic dGltYXJtOnRpbWFybQ==

User-Agent: PostmanRuntime/7.6.0

Host: localhost:8080

accept-encoding: gzip, deflate


It can also be made with a curl command:

curl -i -X GET -H "Accept: application/json" -H "Authorization: Basic dGltYXJtOnRpbWFybQ==" "localhost:/env/dev/rest/folders"


'Authorization' is standard Basic authorisation where the <user>:<password> is base64 encoded. The example shown above is the base64 encoding of timarm:timarm.

The response is in JSON (since application/json is specified in Accept header).

[{"folder":"PLSHARE","description":"PL Shared","write":true},{"folder":"SCSHARE","description":"SC Shared","write":true},{"folder":"TIMARM","description":"My Files","write":true}]

Any errors in the request are shown with an error response status (400) and error content:

HTTP/1.1 400

status: 400

Date: Mon, 18 Feb 2019 16:27:56 GMT

Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips

Cache-Control: no-store, no-cache

Expires: 0

Pragma: no-cache

X-XSS-Protection: 1; mode=block

Strict-Transport-Security: max-age=31536000; includeSubDomains

X-Content-Type-Options: nosniff

Content-Security-Policy: frame-ancestors 'self' https://www.bbc.co.uk; script-src 'self' maps.googleapis.com cdn01.boxcdn.net 'unsafe-inline' 'unsafe-eval'

Referrer-Policy: strict-origin-when-cross-origin

Connection: close

Transfer-Encoding: chunked

Content-Type: application/json

[{"error":"Folder not found"}]

Automated Downloads

It is possible to write scripts that poll the /rest/folders/{folder}/files endpoint to see what files are available:

GET /env/dev/rest/folders/plshare/files

Accept: application/json

Content-Type: application/octet-stream

cache-control: no-cache

Postman-Token: 991d8480-8071-4379-9b39-49426502928e

Authorization: Basic dGltYXJtOnRpbWFybQ==

User-Agent: PostmanRuntime/7.6.0

Host: localhost:8080

accept-encoding: gzip, deflate


responding with:

[{"file":"info.gif","size":145,"modified":"2019-02-11T12:50:20.000","download":true,"MD5":"118d779812eda8d9b5bfbe46a8bfc335"}]


This indicates that there is a file info.gif of size 145 bytes with a modified date/time of 11th Feb. If the download field is true, then it can be downloaded with the request shown below (this checks that the file is no longer being written to). The MD5 hash allows you to check the downloaded file if required.

GET /env/dev/rest/folders/plshare/files/info.gif/download

Accept: application/json

Content-Type: application/octet-stream

cache-control: no-cache

Postman-Token: d5a64ac9-a454-456f-8dbc-0ff5e04bbf66

Authorization: Basic dGltYXJtOnRpbWFybQ==

User-Agent: PostmanRuntime/7.6.0

Host: localhost:8080

accept-encoding: gzip, deflate


responds with:

HTTP/1.1 200

status: 200

Date: Mon, 18 Feb 2019 16:37:10 GMT

Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips

Cache-Control: no-store, no-cache

Expires: 0

Pragma: no-cache

Content-disposition: attachment; filename="info.gif"

X-XSS-Protection: 1; mode=block

Strict-Transport-Security: max-age=31536000; includeSubDomains

X-Content-Type-Options: nosniff

Content-Security-Policy: frame-ancestors 'self' https://www.bbc.co.uk; script-src 'self' maps.googleapis.com cdn01.boxcdn.net 'unsafe-inline' 'unsafe-eval'

Referrer-Policy: strict-origin-when-cross-origin

Keep-Alive: timeout=5, max=100

Connection: Keep-Alive

Transfer-Encoding: chunked

Content-Type: application/octet-stream

GIF89a …


By redirecting the output of a curl command or using a wget command, the binary file can be saved. Once the file has been safely downloaded and the MD5 verified (if required) then a DELETE request can be made:

DELETE /env/dev/rest/folders/plshare/files/info.gif

Accept: application/json

Content-Type: application/octet-stream

cache-control: no-cache

Postman-Token: bd70a423-8c9e-4fc7-a8fd-6ee250dc8de4

Authorization: Basic dGltYXJtOnRpbWFybQ==

User-Agent: PostmanRuntime/7.6.0

Host: localhost:8080

accept-encoding: gzip, deflate

content-length:


The response is the file that was deleted:

{"file":"info.gif","size":145,"modified":"2019-02-11T12:50:20.000","download":true,"MD5":"118d779812eda8d9b5bfbe46a8bfc335"}


and the file has been removed from the var/home/plshare directory.

By setting up linked directories between $BASE/var/archive and /var/home it is possible to have archived reports presented in shared folders for a scripted download. All the REST interface requests are made via https. No other protocol is required.

Upload Files

It is possible to upload files to My Files and Shared Folders using the POST or PUT commands. POST will create a new file but return an error if the file already exists. PUT will create a file OR overwrite it if it already exists.

The path to use to upload files is:

/rest/folders/{folder}/files/{file}

Where {folder} is the folder name and {file} is the name for the file once uploaded. The body of the POST/PUT is the content of the file. The content of the file can be encoded to handle different content.

The URL parameter encoding should be set to one of:

  • BASE64 - base64 encoded - for binary files

  • ASCII - plain text no encoding

  • DOS - plain text - remove DOS carriage return

The response is the details of the newly created file:

{

"file": "string",

"size": 9,

"modified": "1999-12-31T00:00:00.000",

"download": false,

"MD5": "string"

}

Did this answer your question?