- 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:
This page is intended for software developers who would like to access our API in order to build their own applications based on data gathered and combined by Barentswatch.
Prerequisites, licencing and crediting
TODO: The text her should be rewritten to reflect the content linked to.
To use the BarentsWatch API you have to register your application with BarentsWatch. Please see: https://www.barentswatch.no/om/apnedata/
How to connect to the Barentswatch API.
The BarentsWatch API supports Open ID Connect flows (client credentials, authorization code, and device code). In order to access the Barentswatch API you need a Client.
Obtaining a client
You can register your own API client connected to your user. To to so you must first create a user and log in at https://www.barentswatch.no/minside/. Here you can self register clients for use in your application.
Self registered clients only supports Open ID Connect's client_credentials flow. If you need to use something other than credentials flow, you will have to contact BarentsWatch (email@example.com) to set up other types of clients.
The OpenID discovery document is here: https://id.barentswatch.no/.well-known/openid-configuration (production).
Once you have a client (either from self-registration on MyPage/Minside, or obtained from BarentsWatch) you can use the clients ClientID and ClientSecret you can use this information to obtain an Access Token.
How to use the access token
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 'content-type' must be 'application/x-www-form-urlencoded'
- Body must have four key-value pairs, separated by ampersand (&):
- Key 'grant_type' must have value 'client_credentials'
- Key 'client_id' must have your full client ID as value, which is often written like this: firstname.lastname@example.org:myclient. If your client does not url-encode automatically, you must url-encode it like this: myusername%40example.com%3Amyclient
- Key 'client_secret' must have a client secret you have created, as value.
- Key 'scope' must have value 'api'
Example request, using curl:
Example success response:
How to use your access token to access the API
This is an example request to the BarentsWatch API to get available forecast times for a particular fairway.
The same request using 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/
How to log in to the OpenAPI documentation
You can log in to the OpenAPI-documentation with your own client.
- Go to https://www.barentswatch.no/bwapi/openapi/index.html
- Click 'Authorize'
- Below the headline "oauth2 (OAuth2, clientCredentials)":
- Replace client_id with your own client_id. It has to be URL-encoded like this: myusername%40example.com%3Amyclient. You can copy your URL-encoded client_id from MyPage/Minside.
- Enter your client_secret
- Select 'api' scope (tick the box)
- Click 'Authorize', and then 'Close'
You are now logged in.
You can select the API documentation in the dropdown-menu in the upper-right corner.