Python sample

import requests
import json
import sys

username = "username"
password = "password"
url = "https://api-uat.ihsmarkit.com/"
namespace = "namespace"
entity = "entity"
service = "service"

# Authenticate
# This creates an API key needed for the following data requests.
# Reuse the API key as much as possible.
# The API key can be invalidated at any time,
# to challenge a client to re-authenticate.
# If the API key becomes invalid, create a new one
# and retry the failed request.
r = requests.post("https://api-uat.ihsmarkit.com/apikey",
                  data={'username': username,
                        'password': password})
print("POST /apikey", r.status_code, r.reason)
apikey = r.text

if (r.status_code != 200):
    # invalid credentials
    sys.exit();

# Retrieve data from the API,
# from a given namespace, entity and service.
# This retrieves a snapshot of latest records.
path = namespace + '/'+ entity + '/' + service
query = '?limit=3&format=JSON'
req = url + path + query

r = requests.get(req, headers={'Authorization': 'Bearer {}'.format(apikey)});
print(r.status_code, r.text[:100])

if (r.status_code > 499):
    print("Server-side error; handle by retrying")
    sys.exit();

if (r.status_code == 429):
    print("Too many requests, handle by backing off")
    print("for a period and retrying")
    sys.exit();

if (r.status_code > 399):
    print("Client-side error; do not retry")
    sys.exit();

if (r.status_code == 200):
    print("Response is 200 OK; process parsedJson...")
    parsedJson = json.loads(r.text)

Back to help overview