Hooks API

Web Hook

CreateDiscount4

Set up a discount code that implements Bubblehouse rewards and discounts.

Kind Mutation Hook
Method POST
URL The webhook URL you specify, with :name replaced by CreateDiscount4
Authentication JWT HS256 Bearer token

Note that Bubblehouse will generate the discount codes on our end, and then will call this hook to set up the code. The customer may already see the code by that time. The expectation is that CreateDiscount hook can complete in the time it takes the customer to use the code.

A zero-amount, zero-percents discount code is valid, and will be used for referral tracking if the referred user is to be rewarded in loyalty points. If you cannot support this, referrals will need to be rewarded with a monetary discount.

All codes created by Bubblehouse should be configured to allow combining with other discount codes as much as possible.

Input

  • code string required

    The discount code string generated by Bubblehouse.

  • title string required

    A human-readable description of the discount.

  • end_time time optional

    Expiration time for this discount code, after which it cannot be used.

    Expiration is optional in case you cannot support it, but it's highly recommended to avoid surprises in the future. If you do support it, though, make sure you can handle expiration one year into the future.

    Omitted if no expiration date is configured for coupons.

  • amount monetary? either amount or percentage required

    A fixed amount of the discount.

  • percentage permyriad? either amount or percentage required

    A percentage discount.

  • min_order_amount monetary? optional

    A minimum order amount that this discount code can apply to.

  • max_uses integer? optional

    A maximum number of times this code can be used.

    In many cases, will be 1.

  • customer_id string? optional

    A customer to limit the discount to. Missing or null means unlimited.

  • customer_email string? optional

    The email of the customer to limit the discount to, if any.

  • context DiscountContext1 required

    The information on the kind of .

    Together with subject_slugs, this property allows you to identify the specific discount coupon being created, in case you want to give some coupons an extra-special treatment beyond the properties provided to this hook.

  • subject_slugs array of string optional

    The slugs identifying the object (vendible or achievement) that resulted in this coupon.

    Together with context, this property allows you to identify the specific discount coupon being created, in case you want to give some coupons an extra-special treatment beyond the properties provided to this hook.

    You can identify Bubblehouse objects by slug. Slugs are human-readable and derived from customer-visible titles, but are stable (do not get invalidated as the title changes) and use a restricted URL-friendly character set. E.g. an object named "Oh My, Great Vendible!" might get oh-my-great-vendible slug. Slugs only contain lowercase latin letters, numbers and dashes. You can see an object's slug in the admin panel.

    Slugs are always unique for a given type of object across their entire history. A numeric suffix like -2 is appended when necessary to make it unique (e.g. great-vendible-2). Bubblehouse keeps a history of slugs that have ever been associated with a given object, and allows using any of them to identify it. So when you rename "Great Milestone" to "Best Savings Month", it gets multiple slugs: ["best-savings-month", "great-milestone"]. The current slug always comes first, followed by older slugs.

    This means that you can manually get a slug from the admin console, put it into your system's configuration, and have your system match it against the list of slugs returned by Bubblehouse. This will continue to operate correctly going forward, regardless of any future renames, and across multiple environments.

    Example: ["free-hat","slippers"]

  • subject_type string optional

    The type of the object idenfitied by subject_slugs.

    You typically don't need to care about this property; context should be enough to know the subject type.

  • product_ids array of string optional

    Limit this discount to only apply to the specified products.

  • collection_ids array of string optional

    Limit this discount to only apply to the products in specified collections.

  • is_per_product boolean optional

    Whether the discount applies to the products or the orders.

    If true, the discount applies to the price of the product, i.e. should reduce the price of each order item matching the product IDs or collection IDs.

    If false, the discount applies once to the entire order, even if multiple items match the product or collection IDs.

    This distinction is only relevant if product or collection IDs are specified. Otherwise, it will always be false.

  • applies_to_one_time_purchases boolean one of applies_to_... must be true

    Whether the discount can be used with one-time purchases, aka the normal ones.

  • applies_to_subscription_purchases boolean one of applies_to_... must be true

    Whether the discount can be used when purchasing a new subscription.

    Ignore if your ecommerce shop does not use subscriptions.

  • applies_to_subscription_renewals boolean one of applies_to_... must be true

    Whether the discount can apply to subsequent subscription cycles.

    Ignore if your ecommerce shop does not use subscriptions.

  • max_subscription_cycles integer? optional

    Limit the number of subscription cycles this discount is effective for.

    When 1, applies to just one cycle. When null, applies to every cycle of a subscription going forward.

    Only relevant when applying the code to a subscription purchase. Ignore if your ecommerce shop does not use subscriptions.

Output

A successful response has no meaningful properties and only contains an ok property always set to true:
{"ok": true}
Previous
Overview