Skip to main content

Overview

The common way to integrate with Stigg is by using Stigg SDKs or API, but it’s also possible to use Stigg’s cloud services and UI to manage your product catalog and subscriptions, but still own a replica of the data, and build a custom integration on top of that. We like to call that “Bring Your Own Solution” (or BYOS) type of integration. If any of the following is true, you might consider the BYOS approach:
  1. You already have an entitlement management solution that provisions customers with access to your product, and switching over is too much effort.
  2. You prefer not to depend on the availability of Stigg cloud services or SDKs for enforcing access to features.
As an alternative to other integration methods, it’s possible to keep using your existing solution (or build one) by sourcing its data from Stigg to keep it in sync. Byos In this tutorial, we’ll run a BYOS application that consumes events from Stigg, over a webhook, stores their data in relational DB, and exposes it over a GraphQL API.
Stigg provides durable queues (e.g., AWS SQS) for delivering notifications instead of webhooks. Contact support if you’d like one provisioned.

Example

We’ll implement a Node.js Express app and use Postgraphile to generate a GraphQL API based on a relational database schema, for which will use PostgreSQL. The full source code is available here. 1. Preparing the DB and the data model Let’s start by preparing the init script that will define the database schema:
2. Creating the endpoint We will populate the above tables with data from Stigg, so for that, we’ll add an endpoint to handle the incoming webhooks:
3. Subscribing to events Add the webhook in Stigg, and point it to /webhook endpoint we’ve just added. Subscribe to the following events:
  • customer.created
  • customer.updated
  • customer.deleted
  • entitlements.updated
  • measurement.reported
  • subscription.created
  • subscription.updated
  • subscription.canceled
  • subscription.expired
  • subscription.trial_expired
4. Writing the event processor We’ll need an event processor to handle the arriving events, extract the relevant state and update our local app’s database:
The full file is available here. 4. GraphQL API To expose the data over an API, we’ll add the postgraphile middleware to our express app:
5. Querying the data Now we can access the generated GraphQL API, to make our life easier we’ll use the GraphiQL interactive UI (at /graphiql) and run queries like so: 6. Entitlement checks Let’s add an endpoint that we can use to perform a check if a customer can access a feature or not, so our other services can use it:
The logic of the checkAccessfunction can be found here.

Source code

For your convenience, we prepared a runnable example project that demonstrates this approach. You can find the source code of the example on GitHub👇

Stigg BYOS integration example

An example of integrating Stigg using webhooks to sync entitlements into your own database, exposing a GraphQL API and access checks.