All NHVR APIs use the REST API (Representational state transfer) an API that uses HTTP requests for communication with web services.
To use the REST API through Python, you will need to connect a library to send HTTP requests. The requests library is the de facto standard for making HTTP requests in Python. To install run the following command.
pip install requests
All API calls require the endpoint URL and a set of headers. Some API calls will also require parameters (GET or DELETE requests) or data (POST or PUT requests.
Login API calls should include the following headers:
Header | Value | Note |
Content-Type | 'application/json' | All calls are made using JSON data structures |
Ocp-Apim-Subscription-Key | Your subscription key for the NHVR Portal API | The subscription key uniquely identifies you to the NHVR Portal API |
The login endpoint uses the POST method and because the subscription key automatically populates your email and password the data body should contain an empty object.
import requests
url = "https://api-public.nhvr.gov.au/auth/users/login"
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'xxxxxxxxxxxxxxxxxxxxxxx',
}
data = '{}'
response = requests.post(url, headers = headers, data = data)
print(response.json())