This function and all other functions in this graphql sdk are deprecated. Please migrate to the new rest api.
This operation is only available on the server.
Required Permissions
promo_code:createaccess_pass:basic:read(optional)
Usage
Copy
Ask AI
import { whopSdk } from "@/lib/whop-sdk";
const result = await whopSdk.promoCodes.createPromoCode({
// The amount off (% or flat amount) for the promo.
amountOff: "some string" /* Required! */,
// The monetary currency of the promo code.
baseCurrency:
"aed" /* Valid values: aed | all | amd | ape | ars | aud | bam | bgn | bhd | bob | brl | bsd | btc | cad | chf | clp | cny | cop | crc | czk | dkk | dop | dzd | egp | etb | eth | eur | gbp | ghs | gmd | gtq | gyd | hkd | huf | idr | ils | inr | jmd | jod | jpy | kes | khr | krw | kwd | lkr | mad | mdl | mga | mkd | mnt | mop | mur | mxn | myr | nad | ngn | nok | nzd | omr | pen | php | pkr | pln | pyg | qar | ron | rsd | rub | rwf | sar | sek | sgd | thb | tnd | try | ttd | twd | tzs | usd | uyu | uzs | vnd | xcd | xof | zar */ /* Required! */,
// Restricts promo use to only users who have churned from the company before.
churnedUsersOnly: true,
// The specific code used to apply the promo at checkout.
code: "some string" /* Required! */,
// The id of the company to create the promo code for.
companyId: "biz_XXXXXXXX",
// Whether this promo code is for existing memberships only (cancelations)
existingMembershipsOnly: true,
// The date/time of when the promo expires.
expiresAt: 1716931200,
// Restricts promo use to only users who have never purchased from the company before.
newUsersOnly: true /* Required! */,
// Restricts promo use to only be applied once per customer.
onePerCustomer: true,
// The IDs of the plans that the promo code applies to. If product_id is
// provided, it will only apply to plans attached to that product
planIds: ["xxxxxxxxxxx"],
// The product to lock the promo code to, if any. If provided will filter out any plan ids not attached to this product
productId: "xxxxxxxxxxx",
// The number of months this promo code is applied and valid for.
promoDurationMonths: 10,
// The type (% or flat amount) of the promo.
promoType:
"flat_amount" /* Valid values: flat_amount | percentage */ /* Required! */,
// The quantity limit on the number of uses.
stock: 10,
// Whether or not the promo code should have unlimited stock.
unlimitedStock: true,
});
Example output
Copy
Ask AI
const result = {
// The ID of the promo.
id: "xxxxxxxxxxx",
// The specific code used to apply the promo at checkout.
code: "some string",
// The type (% or flat amount) of the promo.
promoType: "flat_amount" /* Valid values: flat_amount | percentage */,
// The duration of the promo.
duration: "forever" /* Valid values: forever | once | repeating */,
// The timestamp of when the promo was created.
createdAt: 1716931200,
// The date/time of when the promo expires.
expirationDatetime: 1716931200,
// The monetary currency of the promo code.
baseCurrency:
"aed" /* Valid values: aed | all | amd | ape | ars | aud | bam | bgn | bhd | bob | brl | bsd | btc | cad | chf | clp | cny | cop | crc | czk | dkk | dop | dzd | egp | etb | eth | eur | gbp | ghs | gmd | gtq | gyd | hkd | huf | idr | ils | inr | jmd | jod | jpy | kes | khr | krw | kwd | lkr | mad | mdl | mga | mkd | mnt | mop | mur | mxn | myr | nad | ngn | nok | nzd | omr | pen | php | pkr | pln | pyg | qar | ron | rsd | rub | rwf | sar | sek | sgd | thb | tnd | try | ttd | twd | tzs | usd | uyu | uzs | vnd | xcd | xof | zar */,
// The amount off (% or flat amount) for the promo.
amountOff: 10,
// The amount off formatted for display.
discountOff: "some string",
// Restricts promo use to only be applied to already purchased memberships.
existingMembershipsOnly: true,
// The number of months the promo is applied for.
numberOfIntervals: 10,
// Indicates if the promo code is live or disabled.
status: "active" /* Valid values: active | archived | inactive */,
// The quantity limit on the number of uses.
stock: 10,
// Whether or not the promo code has unlimited stock.
unlimitedStock: true,
// The amount of times the promo codes has been used.
uses: 10,
// Restricts promo use to only be applied once per customer.
onePerCustomer: true,
// Restricts promo use to only users who have churned from the company before.
churnedUsersOnly: true,
// Restricts promo use to only users who have never purchased from the company before.
newUsersOnly: true,
// The product this promo code applies to
accessPass: {
// The internal ID of the public product.
id: "xxxxxxxxxxx",
// The title of the product. Use for Whop 4.0.
title: "some string",
},
};

