I’m trying to reformat a curl command into shell script as part of an AppleScript. I don’t have something right with the formatting. I get an error that says:
curl: (3) URL rejected: Malformed input to a URL function
curl: (3) bad range specification in URL position 2:
[{id: ImageID, scheme: image}, {id: ImageID, scheme: image}]
^" number 3
The curl code did work in Postman.
. do shell script "curl --location 'https://example.canto.com/api/v1/batch/content'" & "--header 'Content-Type: application/json'" & "--header 'Authorization: Bearer MyToken'" & "--header 'Cookie: JSESSIONID= CookieID'" & "--data '[{'id': 'ImageID', 'scheme': 'image'}, {'id': 'ImageID', 'scheme': 'image'}]'"
All space characters which separate the header and data parameters are missing, you can also insert the spaces inside the string literals but this makes it clearer, the ¬ is just a line separator.
do shell script "curl --location 'https://example.canto.com/api/v1/batch/content'" & space & ¬
"--header 'Content-Type: application/json'" & space & ¬
"--header 'Authorization: Bearer MyToken'" & space & ¬
"--header 'Cookie: JSESSIONID= CookieID'" & space & ¬
"--data '[{'id': 'ImageID', 'scheme': 'image'}, {'id': 'ImageID', 'scheme': 'image'}]'"
Adding the spaces got rid of the malformed URL error. Now I’m getting an error 3000 we ran into an unknown issue. This error only happens when I need to use the data parameter. I have another AppleScript that uses shell script/curl to search for and download images from Canto that works but it only has a URL and the authorization bearer token header. Is there anything else I might be doing wrong?
Please learn how to post code properly.
You put 3 ticks on a separate line (the tick is on the key with the tilde ~, next to the 1 key), then your code, then 3 more ticks on a separate line.