Graphic API upload to a certain library folder | XM Community

Graphic API upload to a certain library folder

  • 8 December 2022
  • 3 replies

I am trying to use the graphic API to upload images (it is a large number so it is easier to use the API rather than upload them via the browser).
I managed to upload them but I want to divide them into folders, which does not seem to work. Here is my code:
headers = {"x-api-token": apiToken }
files = {'file' : (path, open(path, 'rb'), 'image/jpeg'),"folder": graphic_folder}
baseUrl = "https://{0}{1}/graphics/".format(dataCenter,graphic_library_id)
response =, files=files,headers=headers) 
the images get uploaded but they are in the "uncategorized" folder, not the graphic_folder I specified.
Could someone please help me with that? Thanks a lot.

3 replies

Userlevel 1
Badge +1

What solves this for me was to use this line of code to define files instead of yours:
files = {'file' : (graphic_name, open(graphic_path, 'rb'), graphic_type), "folder": (None,foldername)}
where graphic_name, graphic_path, graphic_type are the same parameters defined by you, and foldername is the string you want to name the destination folder on Qualtrics


I'm trying to upload an image from my local machine to the Qualtrics library. The cURL works fine, but the python request does not. Can anyone tell me the cause of the issue?

The CURL code
curl --request POST \\
 --url \\
 --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \\
 --header 'X-API-TOKEN: tokenID' \\
 --form file=@/Users/username/Desktop/pic_1.png \\
 --form folder=foldername

The python code

conn = http.client.HTTPSConnection("")
payload = "-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"name\\"\\r\\n\\r\\npic1.png\\r\\n-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"file\\"\\r\\n\\r\\n@/Users/username/Desktop/pic_1.png\\r\\n-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"contentType\\"\\r\\n\\r\\nimage/png\\r\\n-----011000010111000001101001\\r\\nContent-Disposition: form-data; name=\\"folder\\"\\r\\n\\r\\nfoldername\\r\\n-----011000010111000001101001--\\r\\n\\r\\n"
headers = {
 'Content-Type': "multipart/form-data; boundary=---011000010111000001101001",
 'X-API-TOKEN': "tokenID"
conn.request("POST", "/API/v3/libraries/libraryID/graphics", payload, headers)
res = conn.getresponse()
data =

The error message with the python code is 

{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Missing Content-Type for file part. name=file","errorCode":"MFDP_3"},"requestId":"7a009aca-135f-49bc-b755-6ccfe8b5da1d"}}

but it seems I have specified content-type in the payload.

Userlevel 4
Badge +19

@JinzhenW did you end up finding a solution to this problem? I am experiencing the same issue where I am specifying the contentType in the body but getting a missing Content-Type error

Leave a Reply