Skip to content

Latest commit

 

History

History
243 lines (180 loc) · 20.6 KB

File metadata and controls

243 lines (180 loc) · 20.6 KB

DiscountCodes

Overview

Available Operations

  • list - List discount codes
  • create - Create a discount code
  • delete - Delete a discount code

list

Retrieve a paginated list of discount codes for a partner / a given discount / the whole program.

Example Usage

import { Dub } from "dub";

const dub = new Dub({
  token: "DUB_API_KEY",
});

async function run() {
  const result = await dub.discountCodes.list();

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { DubCore } from "dub/core.js";
import { discountCodesList } from "dub/funcs/discountCodesList.js";

// Use `DubCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const dub = new DubCore({
  token: "DUB_API_KEY",
});

async function run() {
  const res = await discountCodesList(dub);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("discountCodesList failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.ListDiscountCodesRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.DiscountCodeSchema[]>

Errors

Error Type Status Code Content Type
errors.BadRequest 400 application/json
errors.Unauthorized 401 application/json
errors.Forbidden 403 application/json
errors.NotFound 404 application/json
errors.Conflict 409 application/json
errors.InviteExpired 410 application/json
errors.UnprocessableEntity 422 application/json
errors.RateLimitExceeded 429 application/json
errors.InternalServerError 500 application/json
errors.SDKError 4XX, 5XX */*

create

Create a discount code for a partner. The partner's group must already have a discount assigned to it, and the discount code must be associated with a link that is not already linked with another discount code.

Example Usage

import { Dub } from "dub";

const dub = new Dub({
  token: "DUB_API_KEY",
});

async function run() {
  const result = await dub.discountCodes.create();

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { DubCore } from "dub/core.js";
import { discountCodesCreate } from "dub/funcs/discountCodesCreate.js";

// Use `DubCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const dub = new DubCore({
  token: "DUB_API_KEY",
});

async function run() {
  const res = await discountCodesCreate(dub);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("discountCodesCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CreateDiscountCodeRequestBody ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.DiscountCodeSchema>

Errors

Error Type Status Code Content Type
errors.BadRequest 400 application/json
errors.Unauthorized 401 application/json
errors.Forbidden 403 application/json
errors.NotFound 404 application/json
errors.Conflict 409 application/json
errors.InviteExpired 410 application/json
errors.UnprocessableEntity 422 application/json
errors.RateLimitExceeded 429 application/json
errors.InternalServerError 500 application/json
errors.SDKError 4XX, 5XX */*

delete

Delete a discount code for a partner by its unique ID or alphanumeric code. This will also disable the code in your connected discount provider (Stripe, Shopify, or custom via disccount.deleted webhook).

Example Usage

import { Dub } from "dub";

const dub = new Dub({
  token: "DUB_API_KEY",
});

async function run() {
  const result = await dub.discountCodes.delete("dcode_1JVR7XRCSR0EDBAF39FZ4PMYE");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { DubCore } from "dub/core.js";
import { discountCodesDelete } from "dub/funcs/discountCodesDelete.js";

// Use `DubCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const dub = new DubCore({
  token: "DUB_API_KEY",
});

async function run() {
  const res = await discountCodesDelete(dub, "dcode_1JVR7XRCSR0EDBAF39FZ4PMYE");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("discountCodesDelete failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
idOrCode string ✔️ The unique ID (e.g. dcode_...) or alphanumeric code (e.g. ABC123) of the discount code to delete. dcode_1JVR7XRCSR0EDBAF39FZ4PMYE
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.DeleteDiscountCodeResponseBody>

Errors

Error Type Status Code Content Type
errors.BadRequest 400 application/json
errors.Unauthorized 401 application/json
errors.Forbidden 403 application/json
errors.NotFound 404 application/json
errors.Conflict 409 application/json
errors.InviteExpired 410 application/json
errors.UnprocessableEntity 422 application/json
errors.RateLimitExceeded 429 application/json
errors.InternalServerError 500 application/json
errors.SDKError 4XX, 5XX */*