Does AppleScript have a way of interacting with REST APIs?
I realize I can
do shell script curl
AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.
AppleScript scripts are composed, by motivated users like yourself, in AppleScript, an English-like language containing many of the verbs, nouns, adjectives, articles and other English language elements we use every day.
What Is AppleScript? AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself.
In the Script Editor app on your Mac, click the Run button in the toolbar, or press Command-R, to execute the commands in your script.
I would use curl in
do shell script "#curl script here"
If you need help to get the correct curl statement I recommend postman, It helps me really to generate the right code. But remember If you have these: "
to put an escape character in front: \"
.
So for example if i want to do a POST request to
https://api.widerstandsberechner.ch/api.php?firstcolor=red&secondcolor=orange&thirdcolor=yellow&fourthcolor=silver&hasFiveRings=0&resultInText=0
the AppleScript would 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 easy 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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With