API interaction (Python)
Simple example on how to interact with the Extrahorizon API using python
The Extra horizon SDK currently does not support Python, but fear not: it's perfectly possible to interact with the platform through our API!
At https://docs.extrahorizon.com/extrahorizon/api-reference/api-specs you'll find the complete API documentation.
Have a look at the following example which simply prints your user information. Then we'll go over it step by step.
There are 2 methods of make authenticated calls: OAUTH1 & OAUTH2. The easiest way for a task to interact with the API is through the use of OAUTH1 tokens. These tokens can be generated offline and do not expire unless you regenerate them. This saves you from having to refresh & store tokens, which is the case with OAUTH2.\
Getting credentials
There are 4 different credentials passed to the task through environment variables. Of these, CONSUMER_KEY
& CONSUMER_SECRET
are system-wide credentials identifying the OAUTH1 application. These are usually communicated by Extra horizon after commissioning.
ACCESS_TOKEN
& TOKEN_SECRET
are personal tokens which you need to generate. This is fairly straightforware using the Extra horizon API. Using the terminal and curl, you can do:
Note: replace <your.extrahorizon.url>
, <youremail>
, <yourpassword>
with your actual values.
which will return something of the form
Get the token
& tokenSecret
values and pass them to your task as ACCESS_TOKEN
& TOKEN_SECRET
.
Setting up an OAUTH1 session
Here we're using the requests_oauthlib
python library to create an oauth session for us. See also here for more information regarding the OAUTH1 workflow.
Executing an API call
And then finally we can do our API call & print the result. Again, replace the host with the actual url of your Extra horizon installation.
That's it, now you're ready to 🚀!
Last updated