This guide provides example requests using the get-k-index method in several different programming languages:
Requests using different methods and with different parameters can be made by changing the URL and the request body as explained in the API specification. See the demo page for live examples.
Remember to replace YOUR_API_KEY in the examples with your API key.
These examples are for Curl, with the backslash (\) character used to represent line continuation (as in Unix shell scripts).
curl -X POST\ -H "Content_Type: application/json; charset=UTF-8"\ -d '{"api_key": "YOUR_API_KEY", "options": {"location": "Australian region"}}'\ "https://sws-data.sws.bom.gov.au/api/v1/get-k-index"
curl -X POST\ -H "Content_Type: application/json; charset=UTF-8"\ -d '{"api_key": "YOUR_API_KEY", "options": {"location": "Australian region", "start": "2021-12-07 00:00:00", "end": "2021-12-08 00:00:00"}}'\ "https://sws-data.sws.bom.gov.au/api/v1/get-k-index"
These examples are for Python 3, using the Requests library.
import requests url = "https://sws-data.sws.bom.gov.au/api/v1/get-k-index" headers = {'Content-Type': 'application/json; charset=UTF-8'} requestBody = { 'api_key': 'YOUR_API_KEY', 'options': { 'location': 'Australian region'}} response = requests.post(url, headers=headers, json=requestBody) if response.status_code == 200: responseBody = response.json() data = responseBody['data'] print(data) else: responseBody = response.json() errors = responseBody['errors'] print(errors)
import requests url = "https://sws-data.sws.bom.gov.au/api/v1/get-k-index" headers = {'Content-Type': 'application/json; charset=UTF-8'} requestBody = { 'api_key': 'YOUR_API_KEY', 'options': { 'location': 'Australian region', 'start': '2021-12-07 00:00:00', 'end': '2021-12-08 00:00:00'}} response = requests.post(url, headers=headers, json=requestBody) if response.status_code == 200: responseBody = response.json() data = responseBody['data'] print(data) else: responseBody = response.json() errors = responseBody['errors'] print(errors)
These examples are for Microsoft Power Query for Excel.
If you are not familiar with Power Query, follow these steps in Excel to use the code examples given below:
let url = "https://sws-data.sws.bom.gov.au/api/v1/get-k-index", headers = [#"Content-Type"="application/json; charset=UTF-8"], body = Json.FromValue([ api_key = "YOUR_API_KEY", options = [location= "Australian region"] ]), Response = Json.Document(Web.Contents(url, [Headers=headers, Content=body])), data = Response[data] in data
let url = "https://sws-data.sws.bom.gov.au/api/v1/get-k-index", headers = [#"Content-Type"="application/json; charset=UTF-8"], body = Json.FromValue([ api_key = "YOUR_API_KEY", options = [ location= "Australian region", start= "2021-12-07 00:00:00", end= "2021-12-08 00:00:00" ] ]), Response = Json.Document(Web.Contents(url, [Headers=headers, Content=body])), data = Response[data] in data