File Actions

https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID

Below are the various requests that can be performed against the File resource, as well as the expected parameters and the potential responses.

Delete

Deletes a file or directory, if directory all the contents that directory will also be removed.

Method And Url

DELETE https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID

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, file.*, or file.delete.

Request Path Components

Path Component Description Example
APPLICATION_ID ID associated with the application 575ec8687ae143cd83dc4a97
FILE_ID ID associated with the file 575ec76c7ae143cd83dc4a96

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 DELETE \
    https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID

Successful Responses

Code Type Description
200 Success If file was successfully deleted

Error Responses

Code Type Description
400 Error Error if malformed request
404 Error Error if file was not found

Get

Retrieves information on a file

Method And Url

GET https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID

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, file.*, or file.get.

Request Path Components

Path Component Description Example
APPLICATION_ID ID associated with the application 575ec8687ae143cd83dc4a97
FILE_ID ID associated with the file 575ec76c7ae143cd83dc4a96

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/file/FILE_ID

Successful Responses

Code Type Description
200 File Schema file information

Error Responses

Code Type Description
400 Error Error if malformed request
404 Error Error if file was not found

Move

Move a file or the entire contents of a directory

Method And Url

POST https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID/move

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, file.*, or file.move.

Request Path Components

Path Component Description Example
APPLICATION_ID ID associated with the application 575ec8687ae143cd83dc4a97
FILE_ID ID associated with the file 575ec76c7ae143cd83dc4a96

Request Query Parameters

Name Required Description Default Example
name N The new name of the file or directory name=fileA
parentDirectory N The new parent directory for the file or directory to move into. parentDirectory=/new/location/here

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 POST \
    https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID/move

Successful Responses

Code Type Description
201 File Schema Returns a new file or directory that was created by the move, if a directory a job will kick off to move all the directories children.

Error Responses

Code Type Description
400 Error Error if malformed request
404 Error Error if file was not found

Patch

Reupload a file

Method And Url

PATCH https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID

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, file.*, or file.patch.

Request Path Components

Path Component Description Example
APPLICATION_ID ID associated with the application 575ec8687ae143cd83dc4a97
FILE_ID ID associated with the file 575ec76c7ae143cd83dc4a96

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 Patch schema. For example, the following would be a valid body for this request:

{
  "fileSize": 500,
  "contentType": "image",
  "fileDimensions": {
    "width": 200,
    "height": 200
  }
}

Curl Example

curl -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
    -X PATCH \
    -d '{"fileSize":500,"contentType":"image","fileDimensions":{"width":200,"height":200}}' \
    https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID

Successful Responses

Code Type Description
201 File Upload Post Response Successfully updated file and returned a post url to respond with

Error Responses

Code Type Description
400 Error Error if malformed request
404 Error Error if file was not found

Upload

Uploads the file

Method And Url

POST https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID/upload

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, file.*, or file.upload.

Request Path Components

Path Component Description Example
APPLICATION_ID ID associated with the application 575ec8687ae143cd83dc4a97
FILE_ID ID associated with the file 575ec76c7ae143cd83dc4a96

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 a multipart form data post containing the following:

Name Required Description Default Example
file Y The content of the file to upload

Curl Example

curl -H 'Content-Type: multipart/form-data' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
    -X POST \
    -F file=@localfilename' \
    https://api.losant.com/applications/APPLICATION_ID/file/FILE_ID/upload

Successful Responses

Code Type Description
200 File Schema Updated file content

Error Responses

Code Type Description
400 Error Error if malformed request
404 Error Error if file was not found

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.