Skip to main content

How to add new media to your DAM via the Quable API?

Lucien Berkani avatar
Written by Lucien Berkani
Updated over a year ago

Quable allows you to push your assets via API.

You can add an asset either:

  • With an external link,

  • or by adding your asset file in the Quable CDN, with a so-called internal link.

With an external link:

Here is an example with Python, which calls the [POST] /api/assets API:

import requests
import json

url = "{{host}}/api/assets"

payload = json.dumps({
"id": "sweat-capuche-bleu",
"classification": {
"id": "dam_sort"
},
"attributes": {
"media_nom_photographe": {
"fr_FR": "John Doe"
}
},
"remotePath": "https://www.mydomain.com/myfile.jpg"
})
headers = {
'Accept': 'application/ld+json',
'Authorization': 'Bearer {{pim_token}}',
'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Note that, in this case, the Quable DAM references the provided asset, but the binary source of the file remains the URL you provided (remotePath).

With an internal link:

In this case, you have to make two API calls:

  • the first one to load your media file in the Quable storage

  • the second one to create your asset in your DAM

Upload your media file:

Here is an example with Python, which calls the [POST] /api/files API:

import requests

url = "{{host}}/api/files"

payload={'fileType': 'asset'}
files=[
('file',('file',open('/path/to/file','rb'),'application/octet-stream'))
]
headers = {
'Authorization': 'Bearer {{pim_token}}'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

The JSON response returns an "id" :

{
"id": "__ID__",
"name": "your_file_name.jpg",
"location": {
"container": "your_pim_instance",
"filename": "98c0640d-dfbe-429f-9802-28f9ad7f9d54"
},
"metadatas": {
"mime_type": "image/jpg"
},
"status": "available",
"type": "asset",
"dateCreated": "2023-04-26T14:41:12+00:00",
"dateModified": "2023-04-26T14:41:12+00:00"
}

Associate this file to an asset in Quable DAM:

You then use this ID to create an asset record in the Quable DAM, as in the example below:

import requests
import json

url = "{{host}}/api/assets"

payload = json.dumps({
"id": "sweat-capuche-bleu",
"file": {
"id": "__ID__"
},
"classification": {
"id": "dam_sort"
},
"attributes": {
"media_nom_photographe": {
"fr_FR": "John Doe"
}
}
})
headers = {
'Authorization': 'Bearer {{pim_token}}',
'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

In this case, the download link of your asset sheet points to the Quable CDN.

It has the following format:

Did this answer your question?