Uploading Files via the API
Purpose: Upload files to StorageLink through the REST API as an admin user
Authentication: POST https://<host>/backend/login with x-www-form-urlencoded fields grant_type=password, username and password of the web admin; the response returns the access_token
Client Credentials (optional): Basic Auth with security.client-id and security.client-secret from /opt/swiftgw/application.properties. If you send them, they must be correct
Upload: POST https://<host>/backend/1.0.0/filesystem/<path> with the access_token as a Bearer token and the file as form-data key data; success returns 204 No Content. Folders in <path> that don't exist yet are created
Network: Allow your IP address on port 443 in your Security Group or firewall
API Docs: OpenAPI JSON for StorageLink 1.3.1. Download it, then open it in https://editor.swagger.io with File > Import File
Product: StorageLink by Thorn Technologies — cloud storage gateway for secure file sharing
Overview
In this article, we'll go over the process of how to upload files to StorageLink via the API.
In my examples, I am going to be using Postman, which you can download here: https://www.postman.com/downloads/
View the API documentation
The StorageLink API reference describes every endpoint of StorageLink 1.3.1 in OpenAPI 3.1 format:
To browse it:
Download the file, for example with
curl -O https://thorntech-public-documents.s3.amazonaws.com/storagelink/KB/storagelink-api-documentation-swagger.jsonClick File > Import File and select the downloaded
storagelink-api-documentation-swagger.json
The right side of the editor shows the endpoints grouped by area, with the request and response format of each one. Enter your instance's hostname or IP address in the host server variable to see the full URLs.

All endpoint paths are relative to https://<your-host>/backend. For example, the /1.0.0/filesystem endpoint is at https://<your-host>/backend/1.0.0/filesystem.
When running these commands from your workstation/Postman, make sure your IP address is whitelisted for the port 443 rule in your Security Group/Firewall since that's the port we're sending the requests to.
Generating the OAuth token
In order to make the necessary API calls, we need to obtain an OAuth token, which can be generated via Postman.
To generate the OAuth token, you need the web admin's username and password.
You can also send the application's client ID and secret, security.client-id and security.client-secret, with HTTP Basic Auth. This is optional: StorageLink issues the token without them, but rejects the request with 401 invalid_client if you send values that don't match. To show them, run this command on the server:
sudo grep -E '^security.client-(id|secret)=' /opt/swiftgw/application.properties
Then, in Postman, use the POST method and set the endpoint as this value (use your own IP address or hostname):
https://<your-host>/backend/login
Optionally, under the Authorization tab, select Basic Auth and put your client id as the Username and client secret as the Password.

Next, go to the Body tab and use the x-www-form-urlencoded option. Then, enter in these Key & Values:
grant_type: The literal string: password
username: The username of the web admin user
password: The password of the web admin user

If you click Send, this will then generate the OAuth / access_token:

Now that we have the OAuth token, we can upload files via the API, which is the next section.
The same request with curl:
curl --silent 'https://<your-host>/backend/login' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=password' --data-urlencode 'username=<admin-username>' --data-urlencode 'password=<admin-password>'
To send the client ID and secret as well, add --user '<client-id>:<client-secret>'. The body must be x-www-form-urlencoded; a multipart (--form) body is rejected with 400.
Uploading files via the API
In Postman, open a new tab and use this endpoint:
https://<your-host>/backend/1.0.0/filesystem/
The above endpoint points to the root / directory. If you'd like to upload to a specific path, specify it after the last forward slash, for example:
https://<your-host>/backend/1.0.0/filesystem/Uploads/Bryce
If a folder in the path doesn't exist yet, StorageLink creates it.
In the new tab, set the Authorization tab to use a Bearer Token and paste in the access_token you generated in the previous section.

Next, go to the Body tab and this time we will use the form-data option.
For the Key, set this to data and change it from Text to File. This way, you're able to select a file from your local machine to upload to the server.
Once you've selected the files from your local machine, to upload them, click Send. The server will return a 204 No Content response, but if you check StorageLink, those files will be uploaded. You can add several files to the same request.
Here is an example screenshot of me uploading a file called API-Testing-StorageLink.txt to the /Uploads/Bryce directory.

View in StorageLink:

The same upload with curl:
curl --silent --location 'https://<your-host>/backend/1.0.0/filesystem/Uploads/Bryce' --header 'Authorization: Bearer <access_token>' --form 'data=@"/path/to/API-Testing-StorageLink.txt"'
