Solved

Error calling /assets from CMApi

  • 19 August 2022
  • 3 replies
  • 328 views

Userlevel 3
Badge

I’m trying to upload a document using the /assets api found here: https://www.contentstack.com/docs/developers/apis/content-management-api/#upload-asset

 

I have modified my curl command to look like the one in the documents (removing some non-needed optional parameters):

 

 curl -X POST https://api.contentstack.io/v3/assets?relative_urls=true
-H 'api_key: redacted'
-H 'authorization: redacted'
-H 'content-type: multipart/form-data'
-F 'asset[upload]=/home/tmarshall/Downloads/My-pdf.pdf'

And the error I am getting back is:

{"error_message":"We're sorry, but something went wrong. We've been notified about this issue and will take a look at it shortly. Please contact support@contentstack.com for assistance.","error_code":194}

Please advise!

icon

Best answer by Saqlain 22 August 2022, 08:10

View original

3 replies

Userlevel 1
Badge

Hi Tyler,

I checked the curl command you shared. Seems like the command is not able to access the file location and instead of accepting the file as location it is treated just as a text. You can modify the command to get it working. Here is an working example:

 

curl --location --request POST 'https://api.contentstack.io/v3/assets?relative_urls=true' \

--header 'api_key: redacted' \

--header 'authorization: redacted' \

--form 'asset[upload]=@"/Users/saqlainkali/Downloads/image.png"'

 

I hope this helps!

Userlevel 3
Badge

Hi @Saqlain,

 

While I can post correctly using CURL to that url, I am having troubles doing it thru nodejs/axios. I appear to be consistently getting the same error I had previously.

 

I see that if I do not submit the header of `content-type: multipart/form-data` then a `Content-Type:multipart x-www-form-urlencoded` gets set instead. I’ve set both below… I am not sure if this is expected? Here is my headers being sent:

 

 

{
"message": "Request failed with status code 500",
"name": "AxiosError",
"config": {
"transitional": {
"silentJSONParsing": true,
"forcedJSONParsing": true,
"clarifyTimeoutError": false
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1,
"env": {},
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "multipart/form-data; boundary=--------------------------806978901154770207635157",
"api_key": "redacted",
"authorization": "redacted",
"User-Agent": "axios/0.27.2",
"content-type": "multipart/form-data; boundary=--------------------------672053836125832480963207"
},
"method": "post",
"url": "https://api.contentstack.io/v3/assets?relative_urls=true",
"data": {
"_overheadLength": 339,
"_valueLength": 175,
"_valuesToMeasure": [],
"writable": false,
"readable": true,
"dataSize": 0,
"maxDataSize": 2097152,
"pauseStreams": true,
"_released": true,
"_streams": [],
"_currentStream": null,
"_insideLoop": false,
"_pendingNext": false,
"_boundary": "--------------------------672053836125832480963207",
"_events": {},
"_eventsCount": 1
}
},
"code": "ERR_BAD_RESPONSE",
"status": 500
}

Thanks in advance

Userlevel 3
Badge

Ah, I resolved this, I had to FS read in the file, and cannot specify a filename locally. 

Reply