Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Coupons

*# API Overview

Use the Coupons API to create, modify, retrieve, and delete coupons for a given channel. You can also use it to create and retrieve coupon codes using a couponID.

Coupons must be added as a qualifier to a campaign before they can be used.

For more information, see Using Coupons as Qualifiers in the Salesforce B2C Commerce Infocenter.

Authentication & Authorization

The client requesting the coupon's information must have access to the Coupon resource. For resource access, you must use a client ID and client secret from Account Manager to request an access token. The access token is used as a bearer token and added to the Authorization header of your API request. The client must first authenticate against Account manager to log in.

You must include the relevant scope(s) in the client ID used to generate the token. For details, see Authorization Scopes Catalog.

For detailed setup instructions, see Authorization for Admin APIs.

Use Cases

Single-Use Coupon

Single-use coupons are your standard coupons, which you can only use once per customer.

For example, use the Coupons API to create a coupon with a single coupon code that can be applied only once per order per customer.

Multiple-Use Coupon

A multiple-use coupon can be used any number of times by any number of customers.

For example, use the Coupons API to create a coupon that can be applied once per order and has system-generated codes.

Search Coupon

Use the Coupons API to search for coupons using simple or complex querying.

Search Coupon Redemptions

Use the Coupons API to search for coupon redemptions using simple or complex querying.

For more detail, see Coupon Redemption in the Salesforce B2C Commerce Infocenter.*

For instructions on how to retrieve access token for admin APIs: https://developer.salesforce.com/docs/commerce/commerce-api/guide/authorization-for-admin-apis.html

Example with admin auth

import { Coupons, ClientConfig } from "commerce-sdk";
// or
const { Coupons, ClientConfig } = require("commerce-sdk");

const clientConfig: ClientConfig = {
  parameters: {
    clientId: "XXXXXX",
    organizationId: "XXXX",
    shortCode: "XXX",
    siteId: "XX"
  }
};

token = { access_token: 'INSERT_ACCESS_TOKEN_HERE' };

clientConfig.headers['authorization'] = `Bearer ${token.access_token}`;
const couponsClient = new Coupons(clientConfig);
API Version: 1.4.4
Last Updated:

Hierarchy

  • BaseClient
    • Coupons

Index

Constructors

constructor

  • new Coupons(config: ClientConfig): Coupons
  • Parameters

    • config: ClientConfig

    Returns Coupons

Properties

clientConfig

clientConfig: ClientConfig

Methods

couponRedemptionsSearch

  • The Coupon Redemption Search document contains a search object that allows filtering on various attributes.

    The following searchable query attributes can be used to narrow down the search:

    Attribute Type
    code String
    couponId String
    customerEmail String
    orderNo String

    Note that only searchable attributes can be used in sorting.

    If the user role does not have the View_Coupon_Codes permission, then the returned coupon codes are masked.

    If you would like to get a raw Response object use the other couponRedemptionsSearch function.

    Parameters

    Returns Promise<CouponRedemptionSearchResult>

    A promise of type CouponRedemptionSearchResult.

  • The Coupon Redemption Search document contains a search object that allows filtering on various attributes.

    The following searchable query attributes can be used to narrow down the search:

    Attribute Type
    code String
    couponId String
    customerEmail String
    orderNo String

    Note that only searchable attributes can be used in sorting.

    If the user role does not have the View_Coupon_Codes permission, then the returned coupon codes are masked.

    Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : CouponRedemptionSearchResult>

    A promise of type Response if rawResponse is true, a promise of type CouponRedemptionSearchResult otherwise.

couponsSearch

  • The Coupon Search document contains a search object that allows filtering on various attributes.

    The following searchable query attributes can be used to narrow the search:

    Attribute Type
    couponId String
    description String
    type one of {"single_code", "multiple_codes", "system_codes"}
    enabled Boolean

    Note that only searchable attributes can be used in sorting.

    If you would like to get a raw Response object use the other couponsSearch function.

    Parameters

    Returns Promise<CouponSearchResult>

    A promise of type CouponSearchResult.

  • The Coupon Search document contains a search object that allows filtering on various attributes.

    The following searchable query attributes can be used to narrow the search:

    Attribute Type
    couponId String
    description String
    type one of {"single_code", "multiple_codes", "system_codes"}
    enabled Boolean

    Note that only searchable attributes can be used in sorting.

    Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : CouponSearchResult>

    A promise of type Response if rawResponse is true, a promise of type CouponSearchResult otherwise.

createCoupon

  • If you would like to get a raw Response object use the other createCoupon function.

    Parameters

    Returns Promise<Coupon>

    A promise of type Coupon.

  • Type parameters

    • T: boolean

    Parameters

    • options: RequireParametersUnlessAllAreOptional<{ body: Coupon; fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ couponId: string; organizationId: string; siteId: string } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions }>

      An object containing the options for this method.

    • Optional rawResponse: T

      Set to true to return entire Response object instead of DTO.

    Returns Promise<T extends true ? Response : Coupon>

    A promise of type Response if rawResponse is true, a promise of type Coupon otherwise.

deleteCoupon

  • If you would like to get a raw Response object use the other deleteCoupon function.

    Parameters

    Returns Promise<void>

    A promise of type void.

  • Type parameters

    • T: boolean

    Parameters

    • Optional options: RequireParametersUnlessAllAreOptional<{ fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ couponId: string; organizationId: string; siteId: string } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions }>

      An object containing the options for this method.

    • Optional rawResponse: T

      Set to true to return entire Response object instead of DTO.

    Returns Promise<T extends true ? Response : void>

    A promise of type Response if rawResponse is true, a promise of type void otherwise.

getCoupon

  • If the user role does not have the View_Coupon_Codes permission, then the returned coupon codes are masked.

    If you would like to get a raw Response object use the other getCoupon function.

    Parameters

    Returns Promise<Coupon>

    A promise of type Coupon.

  • If the user role does not have the View_Coupon_Codes permission, then the returned coupon codes are masked.

    Type parameters

    • T: boolean

    Parameters

    • Optional options: RequireParametersUnlessAllAreOptional<{ fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ couponId: string; organizationId: string; siteId: string } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions }>

      An object containing the options for this method.

    • Optional rawResponse: T

      Set to true to return entire Response object instead of DTO.

    Returns Promise<T extends true ? Response : Coupon>

    A promise of type Response if rawResponse is true, a promise of type Coupon otherwise.

getCouponCodes

  • If you would like to get a raw Response object use the other getCouponCodes function.

    Parameters

    Returns Promise<CouponCodes>

    A promise of type CouponCodes.

  • Type parameters

    • T: boolean

    Parameters

    • Optional options: RequireParametersUnlessAllAreOptional<{ fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ couponId: string; limit?: number; offset?: number; organizationId: string; siteId: string } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions }>

      An object containing the options for this method.

    • Optional rawResponse: T

      Set to true to return entire Response object instead of DTO.

    Returns Promise<T extends true ? Response : CouponCodes>

    A promise of type Response if rawResponse is true, a promise of type CouponCodes otherwise.

redeemCoupon

  • The coupon code must be redeemable.

    Note: Coupon redemptions are evaluated during checkout. A large number of coupon redemptions negatively impacts order creation performance and scale.*

    1. Avoid importing unnecessary coupon redemptions.
    2. Clean up coupon codes and related redemptions when they are no longer required.

    If you would like to get a raw Response object use the other redeemCoupon function.

    Parameters

    Returns Promise<void>

    A promise of type void.

  • The coupon code must be redeemable.

    Note: Coupon redemptions are evaluated during checkout. A large number of coupon redemptions negatively impacts order creation performance and scale.*

    1. Avoid importing unnecessary coupon redemptions.
    2. Clean up coupon codes and related redemptions when they are no longer required.

    Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : void>

    A promise of type Response if rawResponse is true, a promise of type void otherwise.

updateCoupon

  • If you would like to get a raw Response object use the other updateCoupon function.

    Parameters

    Returns Promise<Coupon>

    A promise of type Coupon.

  • Type parameters

    • T: boolean

    Parameters

    • options: RequireParametersUnlessAllAreOptional<{ body: Coupon; fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ couponId: string; organizationId: string; siteId: string } & QueryParameters, CommonParameters>; retrySettings?: OperationOptions }>

      An object containing the options for this method.

    • Optional rawResponse: T

      Set to true to return entire Response object instead of DTO.

    Returns Promise<T extends true ? Response : Coupon>

    A promise of type Response if rawResponse is true, a promise of type Coupon otherwise.

updateCouponCodes

  • If you would like to get a raw Response object use the other updateCouponCodes function.

    Parameters

    Returns Promise<void>

    A promise of type void.

  • Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : void>

    A promise of type Response if rawResponse is true, a promise of type void otherwise.

Generated using TypeDoc