Page tree
Skip to end of metadata
Go to start of metadata

Here are a few example requests for the FiskInfo Reporting API.


1. Get profile

curl 'https://www.barentswatch.no/bwapi/v1/geodata/fishingfacilityprofile' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Authorization: bearer <access_token>'

Example response:

{
  "haveProfile": true,
  "haveDownloadRights": true,
  "fiskinfoProfile": {
    "userId": "exampleuser@example.com",
    "ircs": "LAMA",
    "mmsi": 257728500,
    "vesselName": "ANFIELD"
  }
}

This gets the FiskInfo profle of the logged in user. "haveDownloadRights" must be true to get extended info about fishingfacilities.

"haveProfile" must be true to send reports. The user can only send reports for the vessel in the profile.



2. Get reports and tools for the user


curl 'https://www.barentswatch.no/bwapi/v2/geodata/fishingfacilitychanges' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Authorization: bearer <access_token>'


The user may use several devices to access the same data. For example the barentswatch.no/fiskinfo website, the Sintef Fiskinfo app, and a chart plotter. This endpoint lists all tools and any pending reports.


Confirmed tools: This is tools that have been confirmed, and are visible to all who download the fishingfacilities dataset.

Unconfirmed tools: As these tools have not yet been confirmed, they are only visible to the user. They may be presented in the map in a different style, to inform the user that they have been reported.

Pending reports: Reports that that are waiting to be confirmed. Reports about depoyed tools are also available as unconfirmed_tools.

Declined reports: Reports that have been declined. The reason is available as "responseReason".

Failed reports: Reports that were not sent to KVS because they failed. This should normally not happen.


3. Report a tool as retrieved


This should be one of the tools from confirmed_tools list from the fishingfacilitychanges-endpoint:

curl 'https://www.barentswatch.no/bwapi/v1/geodata/fishingfacilitychange/retrieved/F91DD394-273E-459F-83AA-2016F99A72A1' -H 'Accept: application/json, text/plain, */*' -H 'Content-Type: application/json;charset=utf-8' -H 'Authorization: bearer <token>' --data-raw '{"comment":"","contactpersonemail":"exampleuser@example.com","contactpersonname":"Example User","contactpersonphone":"99999999","ircs":"LK2582","setupdatetime":"2019-06-04T11:33:19.900831+02:00","tooltypecode":"NETS","removeddatetime":"2020-09-22T12:15:49.641Z"}'


After sending a report, the client should refresh the dta from the fishingfacilitychanges-endpoint.


4. Report a new tool as deployed


To report a new tool as deployed:

curl 'https://www.barentswatch.no/bwapi/v1/geodata/fishingfacilitychange/deployed' -H 'Content-Type: application/json;charset=utf-8' -H 'Authorization: bearer <token>' --data-raw '{"comment":"","contactpersonemail":"exampleuser@example.com","contactpersonname":"Example User","contactpersonphone":"99999999","ircs":"LK2582","geometrywkt":"POINT(9.058479177606472 64.04298329759357)","setuptime":"2020-09-22T12:09:52.965Z","tooltypecode":"crabpot"}'


After sending a report, the client should refresh the dta from the fishingfacilitychanges-endpoint.



Device login

Login with a client that is set up with device flow.

1. Start login

When a user wants to log in, the device should make a request to the deviceauthorization endpoint:

curl --location --request POST 'https://id.barentswatch.no/connect/deviceauthorization' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=MyClientId' \
--data-urlencode 'scope=api offline_access' \
--data-urlencode 'client_secret=MyClientSecret123'


Response:

{
"device_code": "HuF-7KISrXG0huI-RoqVdnba9d92zzn3hkEuN86hNeg",
"user_code": "788578139",
"verification_uri": "https://id.barentswatch.no/device",
"verification_uri_complete": "https://id.barentswatch.no/device?userCode=788578139",
"expires_in": 3600,
"interval": 5
}

The user_code is the code the user must enter to complete the login. This code must be displayed to the user, with instructions to go to the verification_uri and enter the code. The verification_uri_complete could be encoded as a QR-code and displayed to the user on the device.

expires_in (seconds) is the time until user_code and device_code expires. If they expire the process has to be restarted.

interval (seconds) is the shortest interval that the device can poll the token endpoint.


2. Poll for token

Now the device can poll every 5 seconds (the interval value) for the token:

curl --location --request POST 'https://id.barentswatch.no/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=MyClientId' \
--data-urlencode 'client_secret=MyClientSecret123' \
--data-urlencode 'device_code=HuF-7KISrXG0huI-RoqVdnba9d92zzn3hkEuN86hNeg' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:device_code'


While waiting for the user to enter the user_code, the response will be:

{
    "error": "authorization_pending"
}


If the user does not enter the user_code, or the device does not pull for token within the expire interval, the process must be restarted, The response will be:

{
    "error": "expired_token"
}


When the user grants access, the response will be:


{
    "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IkU1MDY0NDAxN0NGNDVDQjU5NDRCRDE0ODhCRkU4QjAyQT123c2NzMiLCJ0eXAiOiJhdCtqd3QiLCJ4NXQiOiI1UVpFQVh6MFhMV1VTOUZJaV82TEFxZGdkbk0ifQ.eyJuYmYiOjE2MDA4NDg3MzMsImV4cCI6MTYwMDg1MjMzMywiaXNzIjoiaHR0cHM6Ly9pZC5iYXJlbnRzd2F0Y2gubmV0IiwiYXVkIjoiYXBpIiwiY2xpZW50X2lkIjoiZGV2aWNlIiwic3ViIjoiYmU2YTlmOGUtMzc1MS00YzRiLThlMDgtMzY4ZmJlNWIxMzFkIiwiYXV0aF90aW1lIjoxNjAwNzYzNTYwLCJpZHAiOiJsb2NhbCIsInByZWZlcnJlZF91c2VybmFtZSI6ImFuZGVycy5iYWtrZXZvbGRAYm91dmV0Lm5vIiwiZ2l2ZW5fbmFtZSI6IkFuZGVycyIsImZhbWlseV9uYW1lIjoiQmFra2V2b2xkIiwibmFtZSI6IkFuZGVycyBCYWtrZXZvbGQiLCJyb2xlIjoidXNlciIsImVtYWlsIjoiYW5kZXJzLmJha2tldm9sZEBib3V2ZXQubm8iLCJzY29wZSI6WyJhcGkiLCJvZmZsaW5lX2FjY2VzcyJdLCJhbXIiOlsicHdkIl19.XoxUInlQBI0cElyuXjVxnb9rBPFAucuOivTjUxGHzNLDQaS5ISPBmACsEKY7CKPjBltXE7_vxUbPyN_8Q8B0i-PCa7nOw6HLJ4etvORwy_MwiErCX0KjKQB1g12345EKOBJJncfw49Kdes_X-5Mw8E6eS0ZnWIsqYndgLKfFIUasnybtODcPG1LXYiSAUlz1sPpll-kxTT8cLXGSap3CVdbij8WkLw3oTIdKwZgYJGt47Vrl6Cb5CugiRISJzXolUOW0k2Cm0vBwRkZlUYjlcZo82Zb7dUiMR7otQQBIoQvWnboZ-rcGoMDpWxls2x2NDDqXA0ZfGjTm1MD6GZIMP95o1VxCqsgYP5cJgg23modK2nhcMo-YuFsYH-TW6J7l349AZEt5wl-LI0ZSTPtCbm0c-rUzbzevHnf24nnWN4PiCijwpfuBtdALdUOahn6b7Kf1gmWLjTt1ANGuQ8olzl7cjHitcJZeneDovDghW9GKNNJiGW6r7niE4ej6E8LOnM8Ow1TqlwOhvws09OSgmlqT2AgSXqdz4Om1m-nzLvU85x21jRmVIYHR9PTRyQRWtbsJ0Vdrb-dA1VazrLspxkVK9ndUNRDALtvbuOgqpd2zq8t6ECR-emuYjYCOCnC0Tt00kgpS8oJLJOYS1QbFH5AxGTiUxdUcii_4uT_1eAQ",
    "expires_in": 3600,
    "token_type": "Bearer",
    "refresh_token": "y255GMDNpgn12345UiNQkAYd1cZL-sqmfhjM7xS9bGY",
    "scope": "api offline_access"
}

The access_token is used in the authorization header as bearer token when the device is making requests to the api. 

The refresh_token must be stored with the device and updated every time it is being used. The refresh_token is used to get a new access_token. The refresh_token can only be used once. You get a new refresh_token at the same time you request a new access_token. The refresh_token has an expiration time of TBD.

Expires_in (seconds) is expiration time for the access_token (1 hour).


Refresh tokens

When the access token expires, the tokens can be refreshed using the refresh_token:

curl --location --request POST 'https://id.barentswatch.no/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'refresh_token=y255GMDNpgn12345UiNQkAYd1cZL-sqmfhjM7xS9bGY' \
--data-urlencode 'client_id=device' \
--data-urlencode 'client_secret=MyClientSecret123' \
--data-urlencode 'grant_type=refresh_token'


Response:

{
    "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IkU1KLY0NDAxN0NGNDVDQjU5NDRCRDE0ODhCRkU4QjAyQTc2MDc2NzMiLCJ0eXAiOiJhdCtqd3QiLCJ4NXQiOiI1UVpFQVh6MFhMV1VTOUZJaV82TEFxZGdkbk0ifQ.eyJuYmYiOjE2MDA4NDg4NzUsImV4cCI6MTYwMD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vrj-bdnL3-HTBbNZ5_-8R6ujtEftpZ92sRFjxTjsk-_Hn7u5k-qXEE9J9gtynOgc2poB8dU4MMpPfSG1YAK01d_slyBWnrYohhRFj6wY9GwVXxF7kTadpJlaE",
    "expires_in": 3600,
    "token_type": "Bearer",
    "refresh_token": "SH2bboSkkRPAOkY19627TChzBwdNRvALyen_psqJw7U",
    "scope": "api offline_access"
}

The access_token is used in the authorization header as bearer token when the device is making requests to the api.

The new refresh_token must be stored with the device and replaces the refresh_token used to perform the request. The old refresh_token is no longer valid.

  • No labels