Applescript + REST?

Does AppleScript have a way to interact with REST APIs?

I understand that I can

do shell script curl
+3
source share
1 answer

I would use curl in

do shell script "#curl script here"

If you need help getting the correct curl statement, I recommend postman , it helps me generate the correct code. But remember, if you have: "to put the escape-character front: \".

So, for example, if I want to make a POST request for

https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0

AppleScript will look like this:

do shell script "curl -X POST -H \"Cache-Control: no-cache\" \"https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0\""

And of course, you can easily assign the result as a value:

set res to do shell script "curl -X POST -H \"Cache-Control: no-cache\" \"https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0\""

Hope this helps!

+3
source

All Articles