I'm up against an API that has very sparse documentation. I've tried everything (more below) but the end result is a response from the 3rd party server: The given path's format is not supported.
Here are my requirements for this endpoint (POST):
- A multipart/form-data POST
- A formfield named
json
with a JSON string - A file named
file
Here's the "documentation" I was given (simplified the JSON for clarity)...
---------------------------acebdf13572468
Content-Disposition: form-data; name="json"
Content-Type: application/json
{
"Foo": "bar",
"Bar": "foo"
}
---------------------------acebdf13572468
Content-Disposition: form-data; name="file"; filename="api.jpg"
Content-Type: image/jpeg
<@INCLUDE *C:\Users\johnSmith\Pictures\api.jpg*@>
---------------------------acebdf13572468--
I set up a page on my server so instead of posting to their API, I post to my page so I can see the data that is being posted. I did this because despite my best attempts, I can't get the 3rd party to retrieve the logs to tell me what they are seeing on their end.
Here's the code which produced the output that most closely resembles their "code sample" I pasted above:
<cfhttp method="POST" url="#ApiUrl#" result="CfhttpResult" timeout="30" multipart="yes" multipartType="related">
<cfhttpparam type="header" name="subscription-key" value="#SubscriptionKey#" />
<cfhttpparam type="header" name="developer-key" value="#DeveloperKey#" />
<cfhttpparam type="formField" name="json" value="#Payload#">
<cfhttpparam type="file" name="file" file="#FilePath#" mimetype="#FileMimeType#">
</cfhttp>
Here's the result from posting to a page on my server instead of the API:
-------------------------------7d0d117230764
Content-Disposition: form-data; name="json"
Content-Type: text/plain; charset=UTF-8
{"Foo": "bar","Bar": "foo"}
-------------------------------7d0d117230764
Content-Disposition: form-data; name="file"; filename="E:\WEBROOT\mywebsite.com\wwwroot\content\file\2022\05\test_024808PM.png"
Content-Type: image/png
�PNG
IHDR � � X' �
�iCCPICC Profile H��� TS� �Ͻ鍒�k轷 RB � D%$�� CBP�+�#8���` ��*8*EƂX�0(6� dPQ�� *�
(loads more binary data here)
To me, it looks spot on and matches their example, but I'm still getting the same response.
The multipartType
attribute seemed to be the key, something I have not used before after ~14 years writing ColdFusion. Seems like it adds the necessary headers and separates the file from the JSON.
Can anyone spot something I may be overlooking? I'm desperate for another pair of eyeballs and a sanity check.