Adding Purchases to Cantook Cloud
In order to add a customer’s purchase to Cantook Cloud, in addition to the Cantook Cloud Identifier explained in accounts association, the bookstore must acquire the following two pieces of information related to the purchase:
- Its status document url
- Its access token
With those three items, the bookstore can call the Delivery API.
The acquisition of the status document url and access token, and the Delivery API are explained in this section.
Acquiring status_document_url and access_token for new sales
This section assumes the reader is familiar with the Cantook Hub’s sales declaration API and is already using it. This API has been slightly modified to allow the addition of sales to Cantook Cloud. The response when declaring a sale now contains a JSON document that must be used subsequently to add the sale to Cantook Cloud. The formula for declaring sales is the same as previously used, with a few additions:
-
First, it is necessary to add the parameter output=json to the sales declaration in order to receive metadata about the sale instead of a simple message.
-
The API now returns, within a JSON document, the two pieces of information that will be required when adding the purchase to Cantook Cloud in the following fields: status_document_url and access_token.
When a retail sale is successfully declared with the parameter output=json, in addition to the unchanged HTTP status code 201, the response body contains a JSON document which looks like this:
In case of an error, there is no change; the response is provided in plain text format despite the output=json parameter.
Acquiring status_document_url and access_token for existing sales
In addition to the Sales API modifications, a new API is now available to also allow a bookstore to fetch those same values for an already existing values.
Address: /api/organisations/[ ]/publications/[ ]/sales/[ ]?format=[ ]:organisation_id :publication_id :transaction_id :nature &customer_id=[ ]:customer_id
Method: GET
Parameters description:
Name | Required? | Description |
---|---|---|
organisation_id | Organisation’s id, provided by De Marque | |
publication_id | Publication’s identifier (ISBN, EAN) | |
transaction_id | The sale’s transaction’s unique identifier |
Responses:
HTTP Status | Value | Description |
---|---|---|
200 | OK | A JSON Document that includes status_document_url and access_token. |
400 | The input does not follow the specification | |
401 | access_denied | The caller does not have the necessary permissions for this call |
404 | not_found | The sale could not be found with the given parameters |
503 | service_unavailable | The server is not available |
Example response:
Delivery API
This section explains how the book is “pushed” into Cantook Cloud using its Delivery API
Requirements
-
In order to use the Delivery API to add a purchase, a retailer must first obtain
-
the identifier of a given user as explained in Accounts association using Implicit Flow with Form Post
-
A status document url and an access token, obtained as explained in Acquiring status_document_url and access_token for new sales or Acquiring status_document_url and access_token for existing sales
-
-
Calls to the Delivery API must include an “Authorization” request header, containing a secret string (that will be provided by De Marque) as a bearer token.
Request
Method: POST
Authentication: Bearer Token
End-points
Environment | URL |
---|---|
Production | https://cantook-cloud-delivery-api-prod.demarque.workers.dev/hub |
Staging | https://cantook-cloud-delivery-api-staging.demarque.workers.dev/hub |
Request payload
Name | Required | Description |
---|---|---|
user_id | The user identifier, as returned in the 'sub' claim of the OpenID Connect token. | |
status_document_url | URL to obtain the Status Document from. | |
access_token | The library bearer token. | |
test | The sale is a test |
Example
Responses
Status codes
Status code | Success | Type | Description |
---|---|---|---|
200 | - | The publication already exists in the user’s bookshelf. | |
201 | - | The publication was properly added to the user’s bookshelf. | |
400 | https://cloud.cantook.com/api/error/alreadyDelivered | The sale has already been delivered to another user. | |
400 | https://cloud.cantook.com/api/error/invalidInput | The input is not a valid json document or it does not respect the schema. | |
400 | https://cloud.cantook.com/api/error/revoked | The sale has been revoked. | |
400 | https://cloud.cantook.com/api/error/accountNotFound | No account found for the identifier. | |
401 | - | The bearer token is missing or it’s no longer valid. | |
405 | - | The client is using any method other than POST. | |
502 | https://cloud.cantook.com/api/error/contentProviderNetwork | There was a network problem with the content provider. | |
502 | https://cloud.cantook.com/api/error/contentProviderAuth | There was an authorization problem with the content provider. | |
502 | https://cloud.cantook.com/api/error/contentProvider | There was an unspecified problem with the content provider. |
Response payload
Error handling
Error handling will be handled using the Problem Details JSON Object where:
-
we identify errors using “type” and the URI references listed in the previous section
-
along with “title” to communicate the error descriptions listed in the previous section