TWIPLA 3AS API (1.3.2)

Download OpenAPI specification:Download

Concepts

Terms

  • INTP (Integration Partner) The company that is integrating the analytics as a service solution (3AS)
  • STPs (Server Touchpoints) Credits used to measure data usage for a given website
  • Customer (INTPC integration partner customer) One user of the INTP, can have many websites
  • Website The website where data will be tracked. It has a subscription with a package with a certain limit of STPs. This subscription can be upgraded or downgraded. When the website is created a tracking code snippet is returned that must be embedded within the websites HTML.
  • Package A package has a price and contains a certain number of STPs. They are used when upgrading/downgrading the subscription of a website.

General

The Twipla 3AS approach relies on a straightforward flow of data that can be easily integrated into any backend system.

  1. First thing in the integration process a public/private key must be created. The resulting public key is shared with TWIPLA
  2. The INTP account is created resulting in an intpId (that can be used to create tokens) and a default set of packages
  3. The INTP is then free to create customers and websites with any package

Most endpoints that deal with customers or websites support an external ID which can be provided and then used for all following requests.

For example creating a new customer with a website requires an intpCustomerId and an intpWebsiteId. These must be provided by the INTP and are intended to make integrations easier because there is no need to save any external IDs. Then when getting data about a customer the request is done using the same intpCustomerId provided on creation.

Example implementation flow

  1. Create a new customer with a website
  2. Inject the resulting tracking code in the website's HTML
  3. Create the TWIPLA Dashboard url
  4. Show an iframe to the user with the url created previously
  5. Show a modal to the user to upgrade his subscription
  6. Display all the available packages using the API
  7. After the payment is complete, use the API to upgrade the subscription of the website

Getting started

  1. Create an RSA Key Pair (PEM format)
  2. Send the resulting public key (jwtRS256.key.pub) to the TWIPLA Dev Team
  3. Use the resulting private key to sign an INTP JWT Token which will authenticate all API requests
  4. Use the resulting private key to sign an INTPC JWT Token which will authenticate the TWIPLA Dashboard IFrame request

Authentication

Overview

All authentication is done based on JWT Tokens. These are created and signed by the INTP and validated by the TWIPLA API for each request using the public key provided in the on-boarding.

The token must be sent with every request as a Bearer token in the Authentication header Example:

Authentication: bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c 

JWT tokens can be easily created in most programming languages using an appropriate library from jwt.io

INTP and INTPC Tokens

INTP Token: Integration partner token used for endpoints that deal with modifying customers or websites
INTPC Token: Integration partner customer token used to give access to the dashboard and data of a particular customer

Signing JWTs

Creating an RSA Key pair

  1. Create the keypair: ssh-keygen -t rsa -b 2048 -m PEM -f jwtRS256.key
  2. Convert the public key to PEM: openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

Structure of an INTP 3AS JSON Web Token

  1. Header
{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "UUID" // the id issued by TWIPLA for an INTP, in exchange for `jwtRS256.key.pub`
}
  1. Payload
{
  "roles": [
    "intp"
  ],
  "intp_id": "UUID" // the id issued by TWIPLA for an INTP, in exchange for `jwtRS256.key.pub`
  "exp": 1667215913, // expires at
  "iat": 1667215313 // issued at
}
  1. Signature

To create the signature, you have to use the encoded header, the encoded payload, the generated private key and the algorithm specified in the header (e.g., "RS256").

Structure of an INTPC 3AS JSON Web Token

  1. Header
{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "UUID" // the id issued by TWIPLA for an INTP, in exchange for `jwtRS256.key.pub`
}
  1. Payload
{
  "roles": [
    "intpc"
  ],
  "intp_id": "UUID" // the id issued by TWIPLA for an INTP, in exchange for `jwtRS256.key.pub`
  "intpc_id": "string" // the id issued by the INTP for a customer (INTPC)
  "exp": 1667215913,
  "iat": 1667215313
}
  1. Signature

To create the signature, you have to use the encoded header, the encoded payload, the generated private key and the algorithm specified in the header (e.g., "RS256").

TWIPLA Dashboard IFrame URL

https://stage-dashboard-3as.va-endpoint.com?intpc_token=intpc_jwt_token&externalWebsiteId=intpWebsiteId

  1. intpc_jwt_token
  2. intpWebsiteId - the website id issued by the INTP, the target website in the IFrame Dashboard

Customers

Create INTPC

Create a new INTP Customer

Authorizations:
jwt_intp
Request Body schema: application/json

Data about the INTPC

intpCustomerId
required
string <uuid> (id)
email
required
string <email> (email)
required
object (CreateWebsite)

Responses

Request samples

Content type
application/json
{
  • "intpCustomerId": "7128840a-5347-49a4-8dfa-9022d8dad21a",
  • "email": "mail@visitor-analytics.io",
  • "website": {
    }
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Get all INTPCs

Authorizations:
jwt_intp
query Parameters
page
required
number
pageSize
required
number

Responses

Response samples

Content type
application/json
{
  • "payload": [
    ],
  • "meta": {
    }
}

Get INTPC by INTP issued ID

Authorizations:
jwt_intp
path Parameters
intpCustomerId
required
string

ID issued by INTP

Responses

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Delete INTPC by INTP issued ID

Authorizations:
jwt_intp
path Parameters
intpCustomerId
required
string

ID issued by INTP

Responses

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Packages

Create a new Package

Authorizations:
jwt_intp
Request Body schema: application/json
name
required
string (name)
price
required
number (price)
currency
required
string (currency)
Value: "EUR"
touchpoints
required
number (touchpoints) >= 400
period
required
string (period)
Enum: "monthly" "yearly"

Responses

Request samples

Content type
application/json
{
  • "name": "string",
  • "price": 12.99,
  • "currency": "EUR",
  • "touchpoints": 400,
  • "period": "monthly"
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Get packages

Authorizations:
jwt_intp

Responses

Response samples

Content type
application/json
{
  • "payload": [
    ]
}

Get Package by INTP issued ID

Authorizations:
jwt_intp
path Parameters
packageId
required
string

ID issued by VisitorAnalytics

Responses

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Websites

Create a new website

Authorizations:
jwt_intp
Request Body schema: application/json
intpWebsiteId
required
string <uuid> (id)
intpCustomerId
required
string <uuid> (id)
packageId
required
string <uuid> (id)
domain
required
string <uri> (domain)
billingDate
string <date> (date)

Responses

Request samples

Content type
application/json
{
  • "intpWebsiteId": "7128840a-5347-49a4-8dfa-9022d8dad21a",
  • "intpCustomerId": "7128840a-5347-49a4-8dfa-9022d8dad21a",
  • "packageId": "7128840a-5347-49a4-8dfa-9022d8dad21a",
  • "domain": "bigstuff.visitoranalytics.io",
  • "billingDate": "2023-08-22T08:14:03+00:00"
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Get websites

Authorizations:
jwt_intp

Responses

Response samples

Content type
application/json
{
  • "payload": [
    ]
}

Get Website by INTP issued ID

Authorizations:
jwt_intp
path Parameters
intpWebsiteId
required
string

ID issued by INTP

Responses

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Delete Website by INTP issued ID

Authorizations:
jwt_intp
path Parameters
intpWebsiteId
required
string

ID issued by INTP

Responses

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Subscriptions

Upgrade an active website subscription

Authorizations:
jwt_intp
Request Body schema: application/json
intpWebsiteId
required
string
packageId
required
string <uuid> (id)
trial
boolean
proRate
boolean
Default: true

Responses

Request samples

Content type
application/json
{
  • "intpWebsiteId": "string",
  • "packageId": "7128840a-5347-49a4-8dfa-9022d8dad21a",
  • "trial": true,
  • "proRate": true
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Downgrade an active website subscription

Authorizations:
jwt_intp
Request Body schema: application/json
intpWebsiteId
required
string
packageId
required
string <uuid> (id)

Responses

Request samples

Content type
application/json
{
  • "intpWebsiteId": "string",
  • "packageId": "7128840a-5347-49a4-8dfa-9022d8dad21a"
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Cancel an active website subscription

Authorizations:
jwt_intp
Request Body schema: application/json
intpWebsiteId
required
string

Responses

Request samples

Content type
application/json
{
  • "intpWebsiteId": "string"
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Resume a canceled subscription

Authorizations:
jwt_intp
Request Body schema: application/json
intpWebsiteId
required
string

Responses

Request samples

Content type
application/json
{
  • "intpWebsiteId": "string"
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}

Deactivate a subscription

Authorizations:
jwt_intp
Request Body schema: application/json
intpWebsiteId
required
string

Responses

Request samples

Content type
application/json
{
  • "intpWebsiteId": "string"
}

Response samples

Content type
application/json
{
  • "payload": {
    }
}