Space Weather API

Examples

Overview

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.

Curl examples

These examples are for Curl, with the backslash (\) character used to represent line continuation (as in Unix shell scripts).

get-k-index – latest value

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"

get-k-index – with start and end

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"

Python 3 examples

These examples are for Python 3, using the Requests library.

get-k-index – latest value

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)

get-k-index – with start and end

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)

Microsoft Power Query examples

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:

  1. In a blank Excel worksheet, click the Data tab.
  2. Click Get Data > From Other Sources > Blank Query.
  3. In the Power Query Editor window, click Advanced Editor under the Home tab.
  4. Replace all of the text with your code. Replace YOUR_API_KEY with your API key. If no syntax errors have been detected, click Done.
  5. You may be asked "Please specify how to connect." Click Edit Credentials. In the Access Web Content window that pops up, select Anonymous then click Connect.
  6. A preview of the data should now be available to view and convert to a table, before loading to your worksheet.

get-k-index – latest value

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

get-k-index – with start and end

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