Download document using PHP and API

Here is the way to download the file with given in this thread methods:

  1. First, we need to get the authentication token. For that you can use POST api/2.0/authentication method. After sending the request to API, you will receive such response:
{
    "count": 1,
    "status": 0,
    "statusCode": 201,
    "response": {
        "token": "<your_token>",
        "expires": "2024-05-30T12:47:54.7762210Z"
    }
}

From this part we have to fetch the <your_token> value which will be used for further request.

  1. Second, we have to get the download link for the specified file with GET api/2.0/files/file/{fileId}/presigneduri. From the response we fetch the link to the file marked as <link>:
{
    "count": 183,
    "status": 0,
    "statusCode": 200,
    "response": "<link>"
}
  1. After getting <your_token> and <link>, you can use this to get the file on your machine with specified <document_name> and <ext> (extension), e.g. test.docx:
 curl -X GET -H "Authorization:<your_token>" "<link>"  --output <document_name>.<ext>

Note that I’ve used POSTMAN to send the requests and to get the responses for this demonstration.