Skip to main content
Use this guide when you want an external workflow to change the promotion on a subscription after each order. The example campaign gives customers a larger discount on their next orders when they keep their subscription active. The example campaign works like this:
  • The customer starts with discount code ORDER2EARN for 10% off.
  • After the first confirmed order, the next order gets 20% off.
  • After the second confirmed order, the next order gets 30% off.
  • After the third order, no more campaign discounts are added.

How it works

Regular discount codes apply one promotion until they expire or hit their limits. To change the discount over time, use a webhook and the GraphQL API:
  1. Firmhouse sends an Order Confirmed webhook.
  2. Your webhook handler checks whether the subscription used the campaign discount code.
  3. Your handler fetches the subscription with the GraphQL API.
  4. Your handler checks which campaign promotions have already been applied.
  5. Your handler applies the next promotion with applyPromotionToSubscription.

Requirements

  • A project access token with Write access.
  • Three promotions in Firmhouse, for example 10%, 20%, and 30%.
  • A discount code that applies the first promotion.
  • A deployed HTTP endpoint that can receive Firmhouse webhooks.

Create the promotions and discount code

Create three discounts in Firmhouse, for example:
  • First order discount: 10%
  • Second order discount: 20%
  • Third order discount: 30%
Set Limit discount per customer to 1 for each promotion so the active promotion is disabled after it has been used. Then create a discount code, for example ORDER2EARN, that applies the first discount.

Configure the webhook payload

Create an Order Confirmed webhook in Firmhouse. Include the subscription token and applied discount codes in the payload.
Use Order Confirmed because Firmhouse updates promotion limits when an order is confirmed. When your handler receives the event, it can check whether the current promotion is still active and decide whether to apply the next one. Firmhouse sends webhook payloads as text/plain. If your framework depends on Content-Type to parse JSON automatically, parse the body manually with JSON.parse.

Read the webhook payload

The exact code depends on your runtime. In a JavaScript handler, extract the payload and project access token first.
Exit early when the campaign code is not present.

Define the campaign promotions

Collect the promotion IDs in the order they should be applied. You can find a promotion ID in the URL when editing a discount in Firmhouse:
Then configure the IDs in your handler:
The first promotion ID is the promotion applied by the discount code. Keeping it in the list lets the handler determine what has already been applied.

Fetch the subscription

Fetch the subscription and its applied promotions with getSubscription.

Decide whether to apply the next promotion

If one of the campaign promotions is still active, do not apply another promotion.
Find the first promotion in the campaign list that has not been applied yet.

Apply the next promotion

Apply the next promotion with applyPromotionToSubscription.

Secure the webhook endpoint

Firmhouse supports basic authentication for webhooks. Configure a username and password in the webhook settings, then validate the Authorization header in your handler.
If the credentials do not match, return early without applying a promotion.

Test and deploy

  1. Deploy your webhook endpoint.
  2. Configure the Firmhouse webhook in Apps > Webhooks.
  3. Create a subscription using the campaign discount code.
  4. Complete the first payment so the order is confirmed.
  5. Check your webhook logs.
  6. Open the customer in Firmhouse and verify the next discount was applied.
  7. Deploy the workflow for production events.