Luna API is a REST-service.
For major changes to the api, we will add a new version number to the url, e.g /api/v2/. For smaller changes to the api, we will provide a beta service which includes those changes, before merging the changes into the production version.
We use regular 4xx and 5xx http status codes, as close as possible to the HTTP specification. Some errors will have a message of what went wrong in it. Some errors will respons with json. Do not encode those json error responses, as they might change without proper versioning as described above.
There might be cases where the service can give a successfull response, but the response object is missing some data. In that case, we will include one or more warning messages in the object.
To be able to receive data via Luna API, you have to have an agreement on delivery of weather services from Luna.
Luna API uses OpenID connect to authenticate users. The authentication is a two-step process. First generate an access token by passing the client ID and client secret to the https://login.met.no/auth/realms/External/protocol/openid-connect/token endpoint and then use the access token to get the data from Luna API.
Step 1, generate an access token:
token=$(curl -sd "grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>" "https://login.met.no/auth/realms/External/protocol/openid-connect/token" | jq --raw-output ".access_token")
Step 2, use the access token to get data:
curl -H "Authorization: Bearer $token" '<endpoint>'
import requests
# Replace <client_id> and <client_secret> with actual id and secret as string
client_id = <client-id>
client_secret = <client-secret>
# Specify file endpoints and output filenames. Replace <endpoints> with endpoint-url as string
files_to_download = [
{
'url': <endpoint_example1>,
'filename': 'example1.gs2'
},
{
'url': <endpoint_example2>,
'filename': 'example2.gs2'
}
]
# Get the token
url_token = 'https://login.met.no/auth/realms/External/protocol/openid-connect/token'
data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret
}
response = requests.post(url_token, data=data)
response.raise_for_status() # Check if the request was successful
token = response.json()["access_token"]
headers = {
'Authorization': 'Bearer {}'.format(token)
}
# Download each file in the list
for file_info in files_to_download:
url_resource = file_info['url']
filename = file_info['filename']
resource_response = requests.get(url_resource, headers=headers)
resource_response.raise_for_status() # Check if the request was successful
# Save the response content to a file
with open(filename, 'wb') as file:
file.write(resource_response.content)
# Print a confirmation message
print("File has been downloaded and saved as {}".format(filename))
Offshore forecast has two endpoint formats depending on the file format. We deliver in both json and csv.
https://api.luna.met.no/api/v1/offshore/<ID>/json
https://api.luna.met.no/api/v1/offshore/<ID>/csv
Call the endpoint https://api.luna.met.no/api/v1/offshore/available
to get a list of what offshore
forecasts are available. The ID in the endpoint is the ID-number seen in the available-file relative to the
forecast location.
Contact luna@met.no for information about which endpoints you have available. We plan to make this automatic in the future.