Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Campaigns

*# API Overview

Campaigns enable experiences based on an optional schedule and qualifying criteria.

When an experience is assigned to a campaign, the schedule and qualifiers can only refine the containing campaign. A campaign is defined in the context of a site and is not shared among sites. A campaign can be enabled or disabled. A disabled campaign is inactive and not available to consumers. Enabled promotions contained within a disabled campaign are also inactive.

Qualifiers

Qualifiers are requirements that must be met to enable a campaign's experience.

  • Schedule: A start and end time and date. This can be open ended at one or both ends.
  • Coupon: A coupon
  • Customer Group: Membership in a customer group.
  • Source Code: A code attached to the site URL that identifies where the customer was redirected from.

For more details, see Qualifiers on the Salesforce B2C Commerce Infocenter.

Experiences

Promotion: A monetary discount or bonus item. Promotions can have additional criteria such as quantity or number of products gating the discount.

Authentication & Authorization

The client requesting the campaign information must have access to the Campaign 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

Flash Sales

Use single date promotions when you want to run a campaign for a short period of time.

For example, a '20% Off Black Friday' campaign enables a 20% off promotion for registered customers on Black Friday.

No Date or Time Restrictions

You can also configure promotions with no time or date restrictions. This is useful when running coupon-coded promotions, or qualifier-based promotions that require certain criteria to be met.

For example, a 'Free Shipping' campaign enables a free shipping promotion when the coupon code "freeship" is added to the cart.

Redirections

Use redirection promotions to trigger a promotion when a customer arrives at the storefront from a specific location. You may want to use this when partnering with other resources or running external advertisements.

For example, all users directed from Facebook receive a free hat with purchase.

For more information, see Use Source Codes as Qualifiers 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 { Campaigns, ClientConfig } from "commerce-sdk";
// or
const { Campaigns, 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 campaignsClient = new Campaigns(clientConfig);
API Version: 1.4.4
Last Updated:

Hierarchy

  • BaseClient
    • Campaigns

Index

Constructors

constructor

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

    • config: ClientConfig

    Returns Campaigns

Properties

clientConfig

clientConfig: ClientConfig

Methods

campaignsSearch

  • The query attribute specifies a complex query that you can use to narrow down the search. A subset of these attributes can optionally be used to sort the returned results.

    Attribute Type Sortable
    campaignId String yes
    description String yes
    enabled Boolean yes
    couponId String no
    customerGroup String no
    sourceCode String no
    startDate Date no
    endDate Date no
    lastModified Date no

    These fields can only be used in queries as conjunctions (using AND). If the field is used in a disjunction (OR), an exception is thrown.

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

    Parameters

    Returns Promise<CampaignSearchResult>

    A promise of type CampaignSearchResult.

  • The query attribute specifies a complex query that you can use to narrow down the search. A subset of these attributes can optionally be used to sort the returned results.

    Attribute Type Sortable
    campaignId String yes
    description String yes
    enabled Boolean yes
    couponId String no
    customerGroup String no
    sourceCode String no
    startDate Date no
    endDate Date no
    lastModified Date no

    These fields can only be used in queries as conjunctions (using AND). If the field is used in a disjunction (OR), an exception is thrown.

    Type parameters

    • T: boolean

    Parameters

    Returns Promise<T extends true ? Response : CampaignSearchResult>

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

createCampaign

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

    Parameters

    Returns Promise<Campaign>

    A promise of type Campaign.

  • Type parameters

    • T: boolean

    Parameters

    • options: RequireParametersUnlessAllAreOptional<{ body: Campaign; fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ campaignId: 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 : Campaign>

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

deleteCampaign

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

    Parameters

    Returns Promise<void>

    A promise of type void.

  • Type parameters

    • T: boolean

    Parameters

    • Optional options: RequireParametersUnlessAllAreOptional<{ fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ campaignId: 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.

getCampaign

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

    Parameters

    Returns Promise<Campaign>

    A promise of type Campaign.

  • Type parameters

    • T: boolean

    Parameters

    • Optional options: RequireParametersUnlessAllAreOptional<{ fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ campaignId: 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 : Campaign>

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

updateCampaign

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

    Parameters

    Returns Promise<Campaign>

    A promise of type Campaign.

  • Type parameters

    • T: boolean

    Parameters

    • options: RequireParametersUnlessAllAreOptional<{ body: Campaign; fetchOptions?: RequestInit; headers?: {}; parameters?: CompositeParameters<{ campaignId: 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 : Campaign>

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

Generated using TypeDoc