Files Actions
https://api.losant.com/applications/APPLICATION_ID
/files
Below are the various requests that can be performed against the Files resource, as well as the expected parameters and the potential responses.
Get
Returns the files for an application
Method And Url
GET https://api.losant.com/applications/APPLICATION_ID
/files
Authentication
A valid api access token is required to access this endpoint. The token must include at least one of the following scopes: all.Application, all.Application.cli, all.Application.read, all.Organization, all.Organization.read, all.User, all.User.cli, all.User.read, files.*, or files.get.
Request Path Components
Path Component | Description | Example |
---|---|---|
APPLICATION_ID | ID associated with the application | 575ec8687ae143cd83dc4a97 |
Request Query Parameters
Name | Required | Description | Default | Example |
---|---|---|---|---|
sortField | N | Field to sort the results by. Accepted values are: lastUpdated, type, name, creationDate | lastUpdated | sortField=subject |
sortDirection | N | Direction to sort the results by. Accepted values are: asc, desc | asc | sortDirection=asc |
page | N | Which page of results to return | 0 | page=0 |
perPage | N | How many items to return per page | 100 | perPage=10 |
filterField | N | Field to filter the results by. Blank or not provided means no filtering. Accepted values are: name | filterField=name | |
filter | N | Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering. | filter=myFile | |
type | N | Limit by the type (file or directory) of the file | type=file | |
status | N | Limit the result to only files of this status. Accepted values are: completed, pending | status=completed | |
directory | N | Get files that are inside of this directory | directory=/a/path/ |
Request Headers
Name | Required | Description | Default |
---|---|---|---|
Authorization | Y | The token for authenticating the request, prepended with Bearer |
Curl Example
curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
-X GET \
https://api.losant.com/applications/APPLICATION_ID/files
Successful Responses
Code | Type | Description |
---|---|---|
200 | Files Schema | Collection of files |
Error Responses
Code | Type | Description |
---|---|---|
400 | Error | Error if malformed request |
404 | Error | Error if application was not found |
Post
Create a new file for an application
Method And Url
POST https://api.losant.com/applications/APPLICATION_ID
/files
Authentication
A valid api access token is required to access this endpoint. The token must include at least one of the following scopes: all.Application, all.Application.cli, all.Organization, all.User, all.User.cli, files.*, or files.post.
Request Path Components
Path Component | Description | Example |
---|---|---|
APPLICATION_ID | ID associated with the application | 575ec8687ae143cd83dc4a97 |
Request Headers
Name | Required | Description | Default |
---|---|---|---|
Authorization | Y | The token for authenticating the request, prepended with Bearer |
Request Body
The body of the request should be serialized JSON that validates against the File Post schema. For example, the following would be a valid body for this request:
{
"name": "file.csv",
"type": "file",
"parentDirectory": "/",
"fileSize": 500,
"contentType": "text/csv"
}
Curl Example
curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
-X POST \
-d '{"name":"file.csv","type":"file","parentDirectory":"/","fileSize":500,"contentType":"text/csv"}' \
https://api.losant.com/applications/APPLICATION_ID/files
Successful Responses
Code | Type | Description |
---|---|---|
201 | File Upload Post Response | Successfully created file and returned a post url to respond with |
Error Responses
Code | Type | Description |
---|---|---|
400 | Error | Error if malformed request |
404 | Error | Error if application was not found |
Usage of Response
After making a Files: Post
request to Losant with the information about your file, you will need to make a second request using the information from that response object (the upload
property) to actually place the file onto the cloud storage service.
In the upload
field of the Files: Post response, to perform the actual upload of your file. For example, below is how to use curl
and the values from the response to perform the upload of the file data:
curl -X POST \
-F 'Content-Type=<RESPONSE_OBJECT.upload.fields.Content-Type>' \
-F 'key=<RESPONSE_OBJECT.upload.fields.key>' \
-F 'X-Amz-Algorithm=<RESPONSE_OBJECT.upload.fields.X-Amz-Algorithm>' \
-F 'X-Amz-Credential=<RESPONSE_OBJECT.upload.fields.X-Amz-Credential>' \
-F 'X-Amz-Date=<RESPONSE_OBJECT.upload.fields.X-Amz-Date>' \
-F 'Policy=<RESPONSE_OBJECT.upload.fields.Policy>' \
-F 'X-Amz-Signature=<RESPONSE_OBJECT.upload.fields.X-Amz-Signature>' \
-F 'file=@<YOUR_LOCAL_FILE_PATH>' \
'<RESPONSE_OBJECT.upload.url>'
As another example, here is how you would upload the file contents using JavaScript in a browser:
var filePostResponse = /* result of Losant API Files POST call */;
var fileBlob = /* a blob, buffer, or browser file instance */;
var formData = new FormData();
formData.append('Content-Type',
filePostResponse.upload.fields['Content-Type']);
formData.append('key', filePostResponse.upload.fields.key);
formData.append('X-Amz-Algorithm',
filePostResponse.upload.fields['X-Amz-Algorithm']);
formData.append('X-Amz-Credential',
filePostResponse.upload.fields['X-Amz-Credential']);
formData.append('X-Amz-Date',
filePostResponse.upload.fields['X-Amz-Date']);
formData.append('Policy', filePostResponse.upload.fields['Policy']);
formData.append('X-Amz-Signature',
filePostResponse.upload.fields['X-Amz-Signature']);
formData.append('file', fileBlob);
var xhr = new XMLHttpRequest();
xhr.open('POST', filePostResponse.upload.url, true);
xhr.send(formData);
Was this page helpful?
Still looking for help? You can also search the Losant Forums or submit your question there.