Export Service

See subpages for API-specifications

The export service provides alternatives for retrieving metadata and objects from Bokbasen. This pages contains general information covering all export services, see individual sub pages for the different data and formats that can be retrieved.

Pagination

All reports will require one of two parameters; after or next. The usage of the two parameters differs slightly. The HTTP response will always contain a token that represents a specific "internal timestamp" and can be used as a "cursor". This token can be used in the next request to get all changes since the last request.

The maximum allowed age a of both parameters is currently 180 days but might change in the future. If a customer needs to fetch older information than this, please contact Bokbasen on a case by case basis.

Parameters

Initial with after then with next (persist next from each session)

 

Recursive calls until next doesn’t change

 

Next

Using the next parameter is the recommended way to invoke the report service. It is also the only possible way to implement incremental updates. The HTTP response from all report services will include a header containing a token that represents a specific "internal timestamp" that can be used as a "cursor". This token shall be passed with the next parameter in the subsequent request in order to retrieve all updates since the last request. This requires the customer to save the obtained token from each response and use it in the following request. If the token is lost, a new token can easily be obtained by making a new request using an older next or the after parameter.

After

Using the after parameter will allow clients to request records updated since a specific time. The parameter has a human readable format yyyyMMddHHmmss. The only recommended usage of the after parameter is (1) when non incremental updates are requested (for example all records updated last 2 months) or (2) when the token is lost. A response to a request with an after parameter will include a new cursor in the header as long as the resulting report is not empty. Using the after parameter for incremental updates can result in duplicated updates or "missed" updates. (The cause for this is that the timestamp on which both next and after is based, can be set to a value that is before current time.)

Pagesize

All reports have a default pagesize which is also the maximum pagesize. The client is free to choose a suitable pagesize between 1 and this maximum. If pagesize is omitted, or the requested pagesize exceeds the maximum, the services will handle the request using the default pagesize. All clients requesting reports should use the pagination facility when fetching a large number of records.

Response headers

Next Response header

The Next response header is always present. When the current response does not contain any records the Next response header is unchanged.

The Link response header is only present as long as there are more pages to process. When the current response does not contain any records the Link response header is not present.

Best practice

Using the Link response header is the recommend method to implement pagination. The client should keep sending requests as long as the Link response header is present. After the initial request the Link response header should be used in every subsequent request. 
It is also possible to implement pagination using the Next response header. If so, the client should keep sending requests as long as the Next response header does change from the preceding request.

Error Handling

Feedback

In case the request fails due to validation of request headers or input parameters the client will receive a response consisting of an xml explaining the cause of failure. The elements of the error xml are listed below. For some errors there may be additional elements included for better explanation of the error cause. For non-xml formatted reports the response will be in plain text instead of xml.

HTTP/1.1 HTTP_STATUS_CODE MESSAGE Date: Tue, 01 Apr 2014 10:49:04 GMT Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code></code> <message></message> <error> <errors>

Restrictions 

Restriction

Current value

Restriction

Current value

Default (and max) pagesize for ONIX

Currently: 1000

Soon: 200 Future

Default (and max) pagesize for Object Report

5000

Maximum age of after and next parameters

180 days

Maximum age of Object reference link

24 hours

Allowed time skew between server and Date in request header

15 minutes

Pagination and Pagesize sample

Request with after and thereafter a request using the returned Link header.

> curl -i \ -H "Authorization: Boknett TGT-906-Jaemq9xyI5vDRsy6qs27cubbKQIogwFFccjOgK4GYLB5IFT6E0-login.boknett.no" \ -H "Date: Wed, 11 Jun 2014 19:05:44 GMT" \ 'https://api.boknett.no/metadata/export/onix?subscription=extended&pagesize=100&after=20140501120000' Date: Wed, 11 Jun 2014 19:11:20 GMT Server: Apache-Coyote/1.1 Next: MTI1MTUzNzhjMGQzIzE0Njc1YmFjNDlmIzhmMmU5YTU= Link: <https://api.boknett.no/metadata/export/onix?next=MTI1MTUzNzhjMGQzIzE0Njc1YmFjNDlmIzhmMmU5YTU=&subscription=extended&pagesize=100>; rel="next" Content-Type: application/xml Via: 1.1 api.boknett.no Transfer-Encoding: chunked <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ONIXMessage xmlns="http://ns.editeur.org/onix/3.0/reference" release="3.0"> ... (1-100 records of 150 returned) </ONIXMessage> > curl -i \ -H "Authorization: Boknett TGT-906-Jaemq9xyI5vDRsy6qs27cubbKQIogwFFccjOgK4GYLB5IFT6E0-login.boknett.no" \ -H "Date: Wed, 11 Jun 2014 19:05:44 GMT" \ 'https://api.boknett.no/metadata/export/onix?next=MTI1MTUzNzhjMGQzIzE0Njc1YmFjNDlmIzhmMmU5YTU=&subscription=extended&pagesize=100' Date: Wed, 11 Jun 2014 19:12:45 GMT Server: Apache-Coyote/1.1 Next: MTI1MTUzNzhjMTBjIzE0Njc1YmUyZjY0IzhmMzJhNWM= Link: <https://api.boknett.no/metadata/export/onix?next=MTI1MTUzNzhjMTBjIzE0Njc1YmUyZjY0IzhmMzJhNWM=&subscription=extended&pagesize=100>; rel="next" Content-Type: application/xml Via: 1.1 api.boknett.no Transfer-Encoding: chunked <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ONIXMessage xmlns="http://ns.editeur.org/onix/3.0/reference" release="3.0"> ... (101-150 of 150 records returned) </ONIXMessage>   > curl -i \ -H "Authorization: Boknett TGT-906-Jaemq9xyI5vDRsy6qs27cubbKQIogwFFccjOgK4GYLB5IFT6E0-login.boknett.no" \ -H "Date: Wed, 11 Jun 2014 19:10:46 GMT" \ 'https://api.boknett.no/metadata/export/onix?next=MTI1MTUzNzhjMTBjIzE0Njc1YmUyZjY0IzhmMzJhNWM=&subscription=extended&pagesize=100' Date: Wed, 11 Jun 2014 19:12:45 GMT Server: Apache-Coyote/1.1 Next: MTI1MTUzNzhjMTBjIzE0Njc1YmUyZjY0IzhmMzJhNWM= Content-Type: application/xml Via: 1.1 api.boknett.no Transfer-Encoding: chunked   (No more records. Next unchanged. Link not present in Response)

Parameter Error

Request with valid Authorization token and Date. But is missing mandatory parameter subscription.

> curl -i \ -H "Authorization: Boknett TGT-2-alOe0gIWn4xWh1kVfHpIjcqPgcvoRbHw1AsnoqnlBh41udbEQe-login.boknett.no" \ -H "Date: Wed, 02 Apr 2014 14:45:00 GMT" \ https://api.boknett.no/metadata/export/onix?after=20140319100000   HTTP/1.1 400 Bad Request Content-Type: application/xml Transfer-Encoding: chunked Server: Jetty(8.1.14.v20131031) <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>subscription</code> <message>may not be null</message> </error> </errors>

 

Request with valid Authorization token and Date. But is missing next or after parameter.

> curl -i \ -H "Authorization: Boknett TGT-2-alOe0gIWn4xWh1kVfHpIjcqPgcvoRbHw1AsnoqnlBh41udbEQe-login.boknett.no" \ -H "Date: Wed, 02 Apr 2014 14:45:00 GMT" \ https://api.boknett.no/metadata/export/onix?subscription=basic   HTTP/1.1 400 Bad Request Content-Type: application/xml Transfer-Encoding: chunked Server: Jetty(8.1.14.v20131031) <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>nextAndAfterValid</code> <message>Either parameter next or after must be given. Not both.</message> </error> </errors>

Missing Headers Error

Request missing required headers.

> curl -i https://api.boknett.no/metadata/export/onix?subscription=basic&after=20140319100000   HTTP/1.1 400 Bad Request Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>MissingDateHeader</code> <message>Missing date header</message> </error> <error> <code>MissingAuthorizationHeader</code> <message>Missing authorization header</message> </error> </errors>

Date Header Error

Request with valid Authorization token, and a Date of invalid format.

> curl -i \ -H "Authorization: Boknett TGT-2-alOe0gIWn4xWh1kVfHpIjcqPgcvoRbHw1AsnoqnlBh41udbEQe-login.boknett.no" \ -H "Date: 02.04.2014 11:59:00" \ https://api.boknett.no/metadata/export/onix?subscription=basic&after=20140319100000   HTTP/1.1 400 Bad Request Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>WrongDateFormat</code> <message>Invalid format: 02.04.2014 11:59:00</message> </error> </errors>

 

Request with valid Authorization token, and a Date that is of valid format but is not within the boundary of 15 minutes skew.

> curl -i \ -H "Authorization: Boknett TGT-2-alOe0gIWn4xWh1kVfHpIjcqPgcvoRbHw1AsnoqnlBh41udbEQe-login.boknett.no" \ -H "Date: Wed, 02 Apr 2014 11:59:00 GMT" \ https://api.boknett.no/metadata/export/onix?subscription=basic&after=20140319100000   HTTP/1.1 400 Bad Request Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>RequestTimeTooSkewed</code> <message>The difference between the request time and the current time is too large</message> <maxAllowedSkewMilliseconds>900000</maxAllowedSkewMilliseconds> <requestTime>Wed, 02 Apr 2014 11:59:00 GMT</requestTime> <serverTime>Wed, 02 Apr 2014 14:26:35 GMT</serverTime> </error> </errors>

Authorization Header Error (Boknett) Legacy

Request with expired Authorization token and valid Date.

> curl -i \ -H "Authorization: Boknett TGT-1-alOe0gIWn4xWh1kVfHpIjcqPgcvoRbHw1AsnoqnlBh41udbEQe-login.boknett.no" \ -H "Date: Wed, 02 Apr 2014 14:45:00 GMT" \ https://api.boknett.no/metadata/export/onix?subscription=basic&after=20140319100000   HTTP/1.1 401 Unauthorized Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>AuthenticationFailed</code> <message>TICKET_NOT_FOUND</message> </error> </errors>

 

Request with valid Authorization prefix but invalid token and valid Date.

> curl -i \ -H "Authorization: Boknett LETMEIN" \ -H "Date: Wed, 02 Apr 2014 14:45:00 GMT" \ https://api.boknett.no/metadata/export/onix?subscription=basic&after=20140319100000   HTTP/1.1 401 Unauthorized Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>AuthenticationFailed</code> <message>INVALID_TICKET</message> </error> </errors>

 

Request with invalid Authorization prefix and valid Date.

> curl -i \ -H "Authorization: LETMEIN" \ -H "Date: Wed, 02 Apr 2014 14:45:00 GMT" \ https://api.boknett.no/metadata/export/onix?subscription=basic&after=20140319100000   HTTP/1.1 403 Forbidden Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>AccessDenied</code> <message>No authorization found for given parameter combination</message> </error> </errors>

 

Authorization Header Error (Bearer) Future

Expired or invalid token, or missing Bearer prefix all give 401

> curl -i \ -H "Authorization: LETMEIN" \ -H "Date: Wed, 02 Apr 2014 14:45:00 GMT" \ https://api.bokbasen.io/metadata/export/onix?subscription=basic&after=20140319100000 HTTP/1.1 401 Forbidden www-authenticate: Bearer scope="export:onix" error="invalid_token" error_description="token contains an invalid number of segments"

System Error

When the request is fine, but an unexpected error occurs at the server side, the client will receive the following response.

HTTP/1.1 500 Server Error Content-Type: application/xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <errors> <error> <code>SystemError</code> <message>Something went wrong, please contact Bokdatabasen for more information</message> </error> </errors>

Referenced documents

Document

Description

Document

Description

Onix documentation

See editeur.org where descriptions, schemas and etc is located.
http://www.editeur.org/83/Overview/
Bokbasens use of Onix is described here: ONIX3

Bokbasen XML Specification

Separate specification of Bokbasen XML and the different subscriptions.
"Bokbasen XML_export_EKSTERN.xlsx" 
Delivered on request. 

Bokbasen ONIX Schema

https://api.boknett.no/schema/ONIX_BookProduct_3.0_reference.xsd