Extra Horizon
GitHub
  • Extra Horizon Documentation
  • Getting Started
    • Start familiarizing yourself
  • Tutorials
    • Medical Device Tutorial
      • Preparation
      • Build your first prototype
        • Define a data model
        • Configure your workflows
          • Workflow 1: Analyze a measurement
          • Workflow 2: Create & store a PDF report
          • Workflow 3: Send an e-mail
        • Define your permissions
          • Update your schema with user permissions
          • Update your schema with group permissions
        • Build the Front-End
          • Set up oAuth in your backend
          • Demo login page
      • Summary & Wrap up
    • Polysomnography (PSG) Tutorial
    • Retool - Building dashboards Tutorial
  • FAQ
    • General
  • Services
    • Identity and Access Management
      • User service
        • Users
        • Groups
        • Global roles
        • Configuration
      • Auth Service
        • Applications
        • OAuth2
        • OAuth1
        • MFA
        • OpenID Connect
          • Google Cloud
          • Azure ADFS
    • Data Management
      • File Service
      • Data Service
        • Schemas
        • Documents
        • FAQ Data Service
    • Automation
      • Task Service
        • Functions
        • Tasks
        • API Functions
        • Examples
          • Hello world (JS)
          • Hello world (Py)
          • Hello world (Docker)
        • FAQ
      • Dispatchers Service
      • Event Service
        • System Events
    • Communication
      • Notification Service
        • Notifications
        • Settings
      • Mail Service
    • Other
      • Localization Service
        • Language Codes
      • Template Service
        • Localizations
      • Payments Service
        • Subscriptions
        • Stripe
        • iOS App Store
      • Configurations Service
  • API Reference
    • OpenAPI Specifications
    • 📦Changelog
      • Per-service Changelog
    • Postman Reference Collection
  • Tools
    • SDK
    • CLI
    • Control Center
  • Additional Resources
    • Resource Query Language (RQL)
    • Handling Errors
    • GitHub
    • API interaction (Python)
    • Migration guide: Enabling verification request limiting
  • ExH Platform
    • 🙋Support
    • ⏱️Usage and Performance
    • 🔓Security
    • 🗺️Regions
    • ⚖️Cloud Subscription Agreement
    • 🇺🇸CFR 21 Part 11
Powered by GitBook
On this page

Was this helpful?

  1. Additional Resources

API interaction (Python)

Simple example on how to interact with the Extrahorizon API using python

PreviousHandling ErrorsNextMigration guide: Enabling verification request limiting

Last updated 1 year ago

Was this helpful?

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 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.

from requests_oauthlib import OAuth1Session
import os

def handler(event, context):
    exhConsumerKey = os.environ['API_OAUTH_CONSUMER_KEY']
    exhConsumerSecret = os.environ['API_OAUTH_CONSUMER_SECRET']
    exhAccessToken = os.environ['API_OAUTH_TOKEN']
    exhTokenSecret = os.environ['API_OAUTH_TOKEN_SECRET']

    oauth = OAuth1Session(client_key=exhConsumerKey,
                          client_secret=exhConsumerSecret,
                          resource_owner_key=exhAccessToken,
                          resource_owner_secret=exhTokenSecret)

    result = oauth.get('https://<your.extrahorizon.url>/users/v1/me')
    
    print(result.content)

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

    exhConsumerKey = os.environ['API_OAUTH_CONSUMER_KEY']
    exhConsumerSecret = os.environ['API_OAUTH_CONSUMER_SECRET']
    exhAccessToken = os.environ['API_OAUTH_TOKEN']
    exhTokenSecret = os.environ['API_OAUTH_TOKEN_SECRET']

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.

  • Navigate to the Authentication section

  • On the OAuth Applications page, select or create the oAuth1 application you want to use

  • Create or find the version you want to use and click on Generate

  • You are prompted to fill in your email and password are then able to click Generate

  • The credentials will be received as a credentials.txt file

Setting up an OAUTH1 session

    oauth = OAuth1Session(client_key=exhConsumerKey,
                          client_secret=exhConsumerSecret,
                          resource_owner_key=exhAccessToken,
                          resource_owner_secret=exhTokenSecret)

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.

    result = oauth.get('https://<your.extrahorizon.url>/users/v1/me')
    
    print(result.content)

The token & token secret are personal tokens which you need to generate. This is fairly straightforward using the :

Here we're using the requests_oauthlib python library to create an oauth session for us. See also for more information regarding the OAUTH1 workflow.

That's it, now you're ready to !

🚀
https://docs.extrahorizon.com/extrahorizon/api-reference/api-specs
Extra horizon Control Center
here