Connecting to an API using file input (or Python?)
Posted about 6 years ago by Simon Wiggins
Post a topicPeople who like this
Delete Comment
This post will be deleted permanently. Are you sure?
Code Snippet
Html
Html
Css
JavaScript
Sass
Xml
Ruby
PHP
Java
C#
C++
ObjectiveC
Perl
Python
VB
SQL
Generic Language
I’m looking to connect to an API endpoint that requires a token passed in the header in the form of:
All calls to the API require this token to be passed in the Authorization header:
Authorization: Token TOKEN_VALUE
I’ve successfully done a POST request to the auth url to get the token (and parsed the json) but I can’t see how to then use that token downstream as the auth.
I need to pass that as the header in all requests.
Ideally I'm looking to request a list of datasets (it also gives download URLs) behind the API then filter that list and request each download link with that auth header to download the files to a local folder then process each one in whatever Omniscope job it's intended for.
Any help massively appreciated.
Thanks,
Simon
0 Votes
5 Comments
Simon Wiggins posted about 3 years ago
Perfect Antonio thanks!
0 Votes
Antonio Poggi posted about 3 years ago Admin
Hello Simon,
Yes, this is possible with the new HTTP Batch block we've recently added. You can compose a series of data driven HTTP calls, using input data to compose the request (url, headers, authorization (bearer) http method, body, etc) and getting the response data body and headers as input of another Http request.
Feel free to play on our daily sandbox first to try stuff out http://daily.omniscope.me/Demo/API/HTTP+Batch.iox/
Please confirm this suits your case, happy to jump in a call to further assist you.
1 Votes
Simon Wiggins posted about 3 years ago
Rounding back on this as I don't see anything else on the forum.
Do you have a good solution to doing a token exchange with an API?
I realise it can be fairly easily done in Python but I'm trying to see if it can be done without.
So essentially connecting to the auth/login url with username and password with a HTTP file block.
Receive back the token
Use that token in the next call in a header "Authorization": "Bearer tokenheredkhfakfjdh"
query the API as normal with that header.
Another extension to this, do the token refresh as well?
0 Votes
Antonio Poggi posted over 4 years ago Admin
1 Votes
Steve Spencer posted about 6 years ago Admin
Hi Simon,
We've put together a workflow with a Python block that demonstrates how to do this:
https://omniscope.me/Forums/POST+to+get+auth+token+before+downloading.iox/
You won't be able to execute this locked project, but feel free to copy/paste the Python into your own workflow, or download an IOZ of this project and import it locally.
For convenience here's the python code from inside that project; see comments inline:
1 Votes
Login or Sign up to post a comment