Best way to grab output from a web-based API call?
I can create a URL for a simple API request over HTTP. And I can URL Escape it, to make it safer to use. But I can't see a simple way using the in-built workflow actions to make the HTTP call and capture the resulting text output.
The examples on this site, and the ones in Federico Viticci's eBook, have very few examples of this type of operation. The closest option seems to be to usen the "Open URL" workflow action for the built-in browser, but then the closest variable to get the resulting text from it is [Browser Selection], but that doesn't return anything if there is no selection.
I'm sure I must be missing something simple ... all help gratefully received.
You can write a snippet of python code which does the call and sets the output with the result.
Editorial comes with
requestspackage, which makes the task almost trivial:
import requests, workflow r = requests.get('http://download.finance.yahoo.com/d/quotes.csv?s=EURUSD=X&f=sl1d1t1c1ohgv&e=.csv') # r.text contains the required answer, in this case I'll parse it a bit more rate = r.text.split(",") workflow.set_output(rate)
If you put the above code in a
Run Python Scriptaction, you'll get the current conversion rate from Euro to Dollar (as provided by Yahoo) as the output of the action, which you can use as Input in the next action (eg. to display it in a
Thanks, jldiaz. That looks easier enough to use as I'm a programmer in other languages.
I wonder if there could be a built-in workflow action for this, to make it easier for non-programmers?