Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Register your application

...

Info
titleSummary
  • 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:

Table of Contents
maxLevel3

Intended audience

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

This link contains information about the data Barentswatch gathers and provides access to via our APIshttps://www.barentswatch.no/om/apnedata/ (Norwegain / EnglishNorwegian)Please see  

Information about requirements for using the Barentswatch API can be found here: www.barentswatch.no/om/api-vilkar for information in Norwegian about how to obtain an API user or send an e-mail to  (Norwegian).

If you have any questions or problems connecting (after reading the rest of this page), contact us at post@barentswatch.no 

How to connect to the Barentswatch API.

The BarentsWatch 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.). You will need to register a client with us in order to access the APIs. The OpenID discovery document is here: https://id.barentswatch.no/.well-known/openid-configuration (production).

Prerequisites

You need ClientID and ClientSecret

Registering a Client

In order to access the Barentswatch API you need an Api 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 with 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 (post@barentswatch.no) to set up other types of clients.

Obtaining an Access Token

Once you have a client (either from self-registration on MyPage/Minside, or obtained from BarentsWatch.

Request and use an access token using client_credentials

Obtain your access token

) you can use the clients ClientID and ClientSecret to obtain an Access Token. The Access Token is used for granting access to endpoints providing data. 

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
  • Body must have four key-value pairs, separated by ampersand (&):
    • Key 'grant_type' must
    be
    • have value 'client_credentials'
    Parameter
    • Key 'client_id'
    must be providedParameter
    • must have your full client ID as value, which is often written like this: myusername@example.com:myclient. If your client does not url-encode automatically, you must url-encode it like this: myusername%40example.com%3Amyclient
    • Key 'client_secret' must
    be providedParameter scope must be
    • have a client secret you have created, as value.
    • Key 'scope' must have value 'api'

Note that the client_id, client_secret, scope (and grant_type) need to be sent in the body – not as headers!

Example request, using curl:

Code Block
languagebash
curl -X POST --Hheader "Content-Type: application/x-www-form-urlencoded" -d "client_id=YOUR_CLIENT_ID&scope=api&client_secret=YOUR_CLIENT_SECRET&grant_type=client_credentials" https://id.barentswatch.no/connect/token

...

Code Block
languagejs
{
  "access_token":"MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3",
  "token_type":"bearer",
  "expires_in":3600
}

For more More information see https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/

...

Example request/response, using postman:

Image Added

Using your access token to access the API

This is an example request to the BarentsWatch API for getting to get available forecast times for a particular fairway.-- Header --

Code Block
GET /bwapi/v1/geodata/waveforecast/available/?modelname=folda&fairwayid=1 HTTP/1.1

...


Host: www.barentswatch.no

...


User-Agent: My Application Name

...


Content-Type: application/x-www-form-urlencoded

...


Authorization: bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3
Excerpt
hiddentrue

Important information about API access

To use the BarentsWatch API application developers must first register their applications with BarentsWatch. See Application registration and authentication.

Verifying token

To verify that the token works as expected, you can make a GET request to The same request using curl:

Code Block
languagebash
curl -X GET "https://www.barentswatch.no/bwapi/v1

...

This endpoint requires authentication, and will return http status code 401 when there is something wrong with the token. If you get 200, the request with token was successful.

More information

/geodata/waveforecast/available?modelname=folda&fairwayid=1" --header  "accept: text/plain" --header  "Authorization: Bearer MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3"


These external websites might be useful for developers:

Using your registered client to access 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 by expanding My clients/Mine klienter in 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.


Excerpt
hiddentrue

Important information about API access

To use the BarentsWatch API application developers must first register their applications with BarentsWatch. Please see: https://www.barentswatch.no/om/apnedata/