Smarticle Platform Integration With the Token System (EN)

This Document describes how to integrate the Smarticle platform with your shop. Download PDF-Document »

USE CASE

You sell content on your page but you use the Smarticle marketing page as landing page, for marketing campaigns or for statistics.

Readers that access the marketing page will click on a purchase button which leads them to your shop. Here they purchase content which they can access at the Smarticle platform.

PARAMETERS FOR THE API

  • Each product (magazine or subscription) has a unique Object ID. You can view this Object ID at
    → Magazine group’s export settings
    → HTML5-Viewer/Shop settings→ Product Mapping List
  • You get an API key that is neccessary to access Smarticle’s API. You can get this API key at
    → Magazine group’s export settings
    → HTML5-Viewer/Shop settings→ Token API
  • You find the Group ID in the browser adress bar when you access the group setting. It depends of 10 letters/numbers.
    You can find the Group ID together with the API Token at the Smarticle shop settings.
  • The Customer ID is an ID that you use in your own shop.

API FUNCTIONS

You can register a purchase, generate a token for an existing reader and access content with the token:

Register a purchase

When a reader first purchases an object then you can register this product for the reader with this API endpoint. The cid is the reader’s ID in your shop. You should keep track of your reader’s ID for further tokens.

If a reader purchased a product in the past and you want to give him access again, then you can optionally use a * start_timestamp. If you use no timestamp then the default value is the time of the request.

When the subscription period – starting with the start_timestamp – is exceeded then you will not get a valid token for this request.

• URL: https://app.smarticle.com/api/token/GROUP_ID/generate • Method: POST
• POSTbody:

{
„api_key“: „<user api key>“,
„cid“: „<external customer id>“,
„purchased_object“: „<smarticle object id from the product mapping list>“, „start_timestamp“: <start date of the subscription in unix timestamp, optional

parameter, used just for subscription purchases> }

• Response body:

{„token“: „<the generated token>“}

• Example:

curl -X POST -i ‚http://app.smarticle.com/api/token/ff1a72e275/generate‘ –data ‚{ „api_key“: „test“, „cid“: „new_reader“, „purchased_object“: „140a2de06ae22“, „start_ti- mestamp“: 1554080400}‘

Generate a token for an existing reader

To give an existing reader access to his already purchased products you can generate a new token for the reader.

• URL: https://app.smarticle.com/api/token/GROUP_ID/generate • Method: POST
• POSTbody:

{
„api_key“: „<user api key>“,

„cid“: „<external customer id>“ }

• Response body:

{„token“: „<the generated token>“}

• Example:

curl -X POST -i ‚http://app.smarticle.com/api/token/ff1a72e275/generate‘ –data ‚{ „api_key“: „test“, „cid“: „new_reader“}‘

Token usage in the HTML5 viewer

After you registered a new reader or generated a token for an existing reader you can just redi- rect the reader to:

• https://app.smarticle.com/html5/?ta=GENERATED_TOKEN This will give the reader access to the purchased/owned products.

PITFALLS

Access token API from frontend

Don‘t access the token API from frontend in production!
If you try to use the token API from your shop’s frontend then you will get problems with CORS. This is not recommended anyway because you would expose your API key in the frontend, which would give hackers access to your API functions.

For development (e.g. if you try out the example shop) you can disable CORS protection in your browser.
For example you can start chrome like this:

$> google-chrome –disable-web-security –user-data-dir=“/tmp/chrome“

Weitere Support-Artikel: