omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Best way to grab output from a web-based API call?

    Editorial
    2
    3
    2674
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jgc
      jgc last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • jldiaz
        jldiaz last edited by

        You can write a snippet of python code which does the call and sets the output with the result.

        Editorial comes with requests package, 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(",")[1]  
        workflow.set_output(rate)
        

        If you put the above code in a Run Python Script action, 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 Show Alert).

        1 Reply Last reply Reply Quote 0
        • jgc
          jgc last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors