NAV

API Authentication Help

How to set up authentication in Insomnia REST client

  1. Log into your account.
  2. Select and copy your API key
  3. Create a new request in insomnia, and go to the header tab.
  4. Add a new header with the name authorization, and paste your API key as the value

How to set up authentication in Python using the requests library

The example below assumes you are using the popular Requests library for python. If not, the same basic configuration can be adapted to the library you are using.

  1. Log into your account.
  2. Select and copy your API key
  3. Paste this key into your python code, or load it from an environment variable.
  4. When making a request, set the authorization header to your API key, like so:
    import json, requests
    
    API_KEY = "..." # paste your API key here
    HEADERS = {
        'authorization': API_KEY
    }
    
    url = "https://api.drugbank.com/v1/us/drug_names"
    params = { "q": "Tylenol" }
    response = requests.get(url, params=params, headers=HEADERS)
    print(response.json())

How to set up authentication in Ruby using the Faraday library

The example below assumes you're using the popular Faraday library for ruby. If not, the same basic configuration can be adapted to the library you are using.

  1. Log into your account.
  2. Select and copy your API key
  3. Paste this key into your ruby code, or load it from an environment variable.
  4. When creating a Faraday connection, set the authorization header like so:
    API_KEY = '...' # paste your API key here
    conn = Faraday.new(
      url: 'https://api.drugbank.com',
      headers: {'authorization' => API_KEY}
    )
    
    resp = conn.get('v1/us/drug_names', {q: 'Tylenol'})
    puts resp.body