I would like to automate the use of a REST API and looking for suggestions on the best approach.
The actual use case is creating a lot of shortcut URL’s using the tinycc.com URL shortener service.
I have found sample code using either curl or small python script and wondering the best approach:
Each time I use the workflow, I need to use it for 20 different URL’s. Only one portion of the REST API curl (or equivalent) command line changes, so I need a mechanism to invoke the API 20 times substituting one parameter.
Looking for simplicity, even if not as fully automated as possible.
The workflow is started manually from a Mac.
Should I simply use some kind of shell script directly, or perhaps called from keyboard maestro, shortcuts, AppleScript?
Or some other mechanism to iterate over the parameter substitution even if I just duplicate the curl 20 times into one script file and use a simple editor global replace command each time I run it?
A little bit of manual work each time I run it versus an overly complicated initial development effort and cryptic longer script is a reasonable trade-off for me as right now I am using a manual process via a webpage interactively which is tedious and takes a lot of elapsed time.
It would just be a standard loop sort of structure.
Take a look at this one. It prints lines from a file. You could do similar but just sub in your curl command and have the line as the URL item of data for the API.
Turns out the curl code I had wasn’t correct. I emailed the services developer and they pointed me to another page of sample code that worked better.
Minor newbie thing: I wasn’t able to cut and paste the code right into a terminal commandline window.
I had to put the code into file.txt and then “sh file.txt” to get it to run properly.
No biggie, but as a rusty cmdline person, I’m assuming maybe I needed to quote the entire thing to feed into the cmdline prompt or maybe use a “here doc” thingy?
Now that the basic RESTAPI is working, I assume I can get a parametric loop going to automate what I want and will use the link you mentioned and others to get that working.