Overview Order to download a file

I can download a file by Browser with getfolderpublink link.
The curl
can download file. But it is not documented in pCloud web site. I found it by browser debugging window (F12).
I realize the download API is also not real download. It just get the file meta data for file.
https://api.pcloud.com/getfilelink?fileid={my-file-id}&auth={my-auth}'
Download file by Curl
curl -o {download-file-name} -L -X GET 'https://p-def7.pcloud.com/{full path of my file}' \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $token"
Demo
1 Get Auth ID
https://my.pcloud.com/oauth2/authorize?client_id={my_client_id}&response_type=code

2 Get Access Token & Auth code
https://u.pcloud.com/oauth2/authorize?client_id=9xxxxxx7&response_type=code&auth={auth_id}
Auth
code is important and Access Token
auth=wt9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgX

Get access token with code.
curl -L -X POST 'https://api.pcloud.com/oauth2_token' \
-H 'Content-Type: application/json; charset=utf-8' \
--form 'client_id="9xxxxxxx7"' \
--form 'client_secret="4xxxxxxxxxxxxxxxxX"' \
--form 'code="lKxxxxxxxxxxxxxxxxxxX"'
response
{
"result": 0,
"userid": 18905223,
"locationid": 1,
"token_type": "bearer",
"access_token": "lKxxxxxxxxxxxxxx-My-Token-xxxxxxxxxxxxxxxxxG7"
}
3 Assign environment variable with token name at terminal
$ token="lKxxxxxxxxxxxxxx-My-Token-xxxxxxxxxxxxxxxxxG7"
I will down load one of file Getting started with pCloud.pdf
I need to get fileid
from JSON response.
The "fileid" is 43338896472
curl -L -X GET 'https://api.pcloud.com/listfolder?path=/' \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $token" | jq
{
"result": 0,
"metadata": {
"path": "/",
"name": "/",
"created": "Sat, 17 Sep 2022 23:58:07 +0000",
"ismine": true,
"thumb": false,
"modified": "Sat, 17 Sep 2022 23:58:07 +0000",
"id": "d0",
"isshared": false,
"icon": "folder",
"isfolder": true,
"folderid": 0,
"contents": [
.... other three default directories
{
"name": "Getting started with pCloud.pdf",
"created": "Sat, 17 Sep 2022 23:58:07 +0000",
"videocodec": "",
"thumb": false,
"modified": "Sat, 17 Sep 2022 23:58:07 +0000",
"size": 16371465,
"audiobitrate": 0,
"fps": "0.00",
"comments": 0,
"isfolder": false,
"height": 0,
"rotate": 0,
"fileid": 43338896472,
"videobitrate": 0,
"width": 0,
"hash": 3096725505949383000,
"duration": "0.00",
"path": "/Getting started with pCloud.pdf",
"category": 4,
"audiosamplerate": 0,
"id": "f43338896472",
"isshared": false,
"ismine": true,
"audiocodec": "mp3",
"parentfolderid": 0,
"contenttype": "application/pdf",
"icon": "document"
}
]
5 Get file information by stat API (include file size)
curl -L -X GET 'https://api.pcloud.com/stat?fileid=43338896472' \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $token" | jq
{
"result": 0,
"metadata": {
"name": "Getting started with pCloud.pdf",
"created": "Sat, 17 Sep 2022 23:58:07 +0000",
"videocodec": "",
"thumb": false,
"modified": "Sat, 17 Sep 2022 23:58:07 +0000",
"size": 16371465,
"audiobitrate": 0,
"fps": "0.00",
"comments": 0,
"isfolder": false,
"height": 0,
"rotate": 0,
"fileid": 43338896472,
"videobitrate": 0,
"width": 0,
"hash": 3096725505949383000,
"duration": "0.00",
"category": 4,
"audiosamplerate": 0,
"id": "f43338896472",
"isshared": false,
"ismine": true,
"audiocodec": "mp3",
"parentfolderid": 0,
"contenttype": "application/pdf",
"icon": "document"
}
}
- get
link
information in JSON response
"link": "https://u.pcloud.link/publink/show?code=XZ9xxxxxxxxxxsss6Sk"
curl -L -X GET 'https://api.pcloud.com/getfilepublink?fileid=43338896472' \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $token" | jq
{
"code": "XZ9bBhVZ0lSVBSVb4jJKDXJAJBBJ0FIOs6Sk",
"created": "Sun, 18 Sep 2022 01:15:38 +0000",
"downloadenabled": true,
"type": 1,
"modified": "Sun, 18 Sep 2022 01:15:38 +0000",
"downloads": 1,
"link": "https://u.pcloud.link/publink/show?code=XZ9xxxxxxxxxxsss6Sk", <- I modified the code
"result": 0,
"linkid": 60017201,
"haspassword": false,
"traffic": 16371465,
"views": 20,
"metadata": {
"name": "Getting started with pCloud.pdf",
"created": "Sat, 17 Sep 2022 23:58:07 +0000",
"videocodec": "",
"thumb": false,
"modified": "Sat, 17 Sep 2022 23:58:07 +0000",
"size": 16371465,
"audiobitrate": 0,
"fps": "0.00",
"comments": 0,
"isfolder": false,
"height": 0,
"rotate": 0,
"fileid": 43338896472,
"videobitrate": 0,
"width": 0,
"hash": 3096725505949383000,
"duration": "0.00",
"category": 4,
"audiosamplerate": 0,
"id": "f43338896472",
"isshared": false,
"ismine": true,
"audiocodec": "mp3",
"parentfolderid": 0,
"contenttype": "application/pdf",
"icon": "document"
}
}
8 Get file path and host URL
Host name
array will be different depends on file's attribute(offical default file or personal file)
curl -L -X GET 'https://api.pcloud.com/getfilelink?fileid=43338896472&auth=wt9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgX' \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $token"
{
"result": 0,
"dwltag": "GYYEgtilNwytpYulbsh1UB",
"hash": 3096725505949383041,
"size": 16371465,
"expires": "Sun, 18 Sep 2022 10:53:50 +0000",
"path": "\/cfZRj4OT2Zwk45bAZlKxxxxxxxxxxxxxxxxxxZbRZlJZ0JZKXZmpZSHZY7ZsFZzpZS5ZLa6pViVfwjfcge2gksnF08W9Qwi7\/Getting%20started%20with%20pCloud.pdf",
"hosts": [
"p-def7.pcloud.com",
"c432.pcloud.com"
]
}
9 Finally I can download with Step 8 host name and path
full URL
= Host[0] name
+ path
(remove first two characters \ /)
curl -o guide.pdf -L -X GET 'https://p-def7.pcloud.com/cfZRj4OT2Zwk45bAZlKxxxxxxxxxxxxxxxxxxZbRZlJZ0JZKXZmpZSHZY7ZsFZzpZS5ZLa6pViVfwjfcge2gksnF08W9Qwi7\/Getting%20started%20with%20pCloud.pdf' \
-H "Content-Type: application/json; charset=utf-8" \
-H "Authorization: Bearer $token"

I can download by browser two.
