Good morning, I could not figure out why I kept ge...
# adobe
s
Good morning, I could not figure out why I kept getting this error message when I use CFHTTP to upload a file to a third party API . Many thanks.
here is the response message: {"Value":null,"Status":1,"Message":"An error occurred while attempting to save the attachment."}   Header HTTP/1.1 200 OK Cache-Control: max-age=0,no-cache,no-store,post-check=0,pre-check=0 Content-Type: application/json; charset=utf-8 Expires: Mon, 26 Jul 1997 05:00:00 GMT Vary: Content-Encoding Server: Microsoft-IIS/10.0 Set-Cookie: stl=1gy2ipo2jfdlbwxg40tgmthr; path=/; HttpOnly; SameSite=Lax X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-Frame-Options: sameorigin Date: Tue, 22 Aug 2023 17:28:51 GMT
Code: Cfhttp(URL="#endUrl#", method="POST", multipart="yes", result="local.apiResponse") { cfhttpparam(type="header", name="Access-Control-Allow-Origin", value="*"); cfhttpparam(type="header", name="Access-Control-Allow-Methods", value="POST, GET, OPTIONS, PUT"); cfhttpparam(type="header",name="file",value="#documentsData.file#"); cfhttpparam(type="FormField", name="Filename", value="#documentsData.file#"); cfhttpparam(type="File", name="#documentsData.file#", file="#fileuploaded#"); }
a
I mean... we have only the same info to go on that you do. They're telling you "An error occurred while attempting to save the attachment". [shrug] Are you following their docs properly? Have you tried with some other HTTP client (eg curl or something)?
s
if you can send a link to the API docs for this method, then we could probably help more. I will note that it seems odd that you are putting the the file path/name in 3 cfhttpparams (one as type="header", one as type="formfield", and the other as type="file")
if you could tell us what type of data is in in each of these variables (documentsData.file, fileuploaded) that would also be helpful information.
I am just guessing (based on how you used it) that #documentsData.file# will return the file name, and that #fileuploaded# will return the files contents
s
Thanks Scott and Adam for the quick response. here is more info: It requires a token to call their API. It used to work with coldfusion 2018. but It stopped working after we upgraded the coldfusion 2018 to coldfusion 2021. This mroning I did another test that I was able to use my script to upload a pdf to the third party API in their stage server. But I could not do it to the third party API in their production server. Since they told me that the setting in their production and stage server are the same, I have no idea how to trouble-shoot.
s
This is not the type of thing that would be easy for us to debug for you without specific knowledge of the 3rd party API you are trying to connect to. If it is working when you submit to their stage server, but not on their prod server, I would try to dump the #local.apiResponse# result objects for both calls, then send those to the 3rd party API support and see what they say. Perhaps there is a request id/transactionid/etc that they can use on their side to help diagnose why it is failing on the prod server.
s
Thanks Scott . Yes, I will do it. I really appreciate your help.
j
This is a longshot because you're not getting a communication error, but I'd also check if there are any SSL Certificates that are required (or maybe even expired) that might need to be in your keystore that had been imported for CF2018 but not into CF2021 install.
s
Thanks Jim for the response. I will look into it.