Convert cURL To Applescript

Hi
I am trying to convert a cURL command to AppleScript Using “do shell script”.
I’ve used various hints from previous posts but I’m still running into errors.
Can anyone point out errors in my syntax.

The below script works fine when run in terminal.

I then adapt as.

--Add do shell script Command--
--Place The cURL Inside Double Quotes--
--Replace Double Quotes With Single Quotes--
--Remove Backslashes At End Of Lines--
--You May Also Need To Place All In A Single Line--

do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload --header 'Authorization: Bearer MYTOKEN' --header 'Content-Type: application/octet-stream' --header 'Dropbox-API-Arg: {'path':'/RoomVT/Clown2.jpeg'}' --data-binary @'/Splash.jpeg'"

I still get the error.

“Error in call to API function "files/upload": HTTP header "Dropbox-API-Arg": could not decode input as JSON”

I can’t test but may you try with :

do shell script "curl -X POST " & quoted form of ("https://content.dropboxapi.com/2/files/upload --header 'Authorization: Bearer MYTOKEN' --header 'Content-Type: application/octet-stream' --header 'Dropbox-API-Arg: {" & quote & "path" & quote & ":" & quote & "/RoomVT/Clown2.jpeg" & quote & "}' --data-binary @" & quote & "/Splash.jpeg" & quote)

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 16 avril 2020 15:46:59

I don’t think options (–…) should be quoted. Only its values. See here how you can adapt do shell script version:


do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload 
  --header 'Authorization: Bearer MYTOKEN' 
  --header 'Content-Type: application/octet-stream' 
  --header 'Dropbox-API-Arg: {'path':'/RoomVT/Clown2.jpeg'}' 
  --data-binary @'/Splash.jpeg'"

Or, this way:


do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload" & linefeed & "--header 'Content-Type: application/octet-stream'" & linefeed & "--header 'Dropbox-API-Arg: {'path':'/RoomVT/Clown2.jpeg'}'" & linefeed & "--data-binary @'/Splash.jpeg'"

I think, you should not remove linefeeds (backslashes), because you need to provide to curl command nested structure (here, JSON). But, I am not sure.

The Piyocast website was where I learned how to make calls
Via a NSURLSession. Here’s a link to tagged articles. Just use a
Translator to view site in English.

http://piyocast.com/as/archives/tag/nsurlsession

At the top is his most recent version that is quite
Detailed and may be more than what your looking for.

I would start with the article at the very bottom
As it can introduce you to it in its simplest form:

http://piyocast.com/as/archives/3779