- You need to register a client on MyPage before you can access the API.
- Create an access token using client_credentials, and send this as a bearer token header.
Table of contents:
How to register your application
To use the BarentsWatch API application developers must register their applications with BarentsWatch. Please see: https://www.barentswatch.no/om/apnedata/ (Norwegain / English)
The API supports Open ID Connect flows like client credentials, authorization code, and device code. Self registered clients only supports client_credentials. You must contact BarentsWatch to set up other types of clients.
The OpenID discovery document is here: https://id.barentswatch.no/.well-known/openid-configuration (production).
How to request an access token
You need ClientID and ClientSecret from self-registration on MyPage/Minside, or obtained from BarentsWatch.
An application can obtain a token for use with the BarentsWatch API by posting a token request via HTTPS to https://id.barentswatch.no/connect/token:
- Use HTTPS POST
- URL must be id.barentswatch.no/connect/token
- Header-parameter 'content-type' must be 'application/x-www-form-urlencoded'
- Parameter 'grant_type' must be 'client_credentials'
- Parameter 'client_id' must be provided - use full ID which is often on the form email@example.com:myclient. If your client does not url-encode automatically, you must url-encode it on the form myusername%40example.com%3Amyclient
- Parameter 'client_secret' must be provided
- Parameter scope must be 'api'
Example request using curl:
Example success response:
For more information see https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/
How to use your access token to access the API
This is an example request to the BarentsWatch API for getting available forecast times for a particular fairway.
The same request with curl:
These external websites might be useful for developers:
- List of OAuth libraries: https://oauth.net/code/
- About client_credentials grant https://www.oauth.com/oauth2-servers/access-tokens/client-credentials/