Skip to content

Latest commit

 

History

History
92 lines (63 loc) · 3.12 KB

File metadata and controls

92 lines (63 loc) · 3.12 KB
title description author ms.date ms.topic audience ms.reviewer ms.search.region ms.author ms.search.validFrom ms.dyn365.ops.version ms.assetid
Cookie API overview
This article provides an overview of the application programming interfaces (APIs) in the Microsoft Dynamics 365 Commerce online software development kit (SDK) that are used to set and get cookie data.
samjarawan
09/14/2021
overview
Developer
v-chgriffin
Global
samjar
2019-10-31
Release 10.0.5

Cookie API overview

[!include banner]

This article provides an overview of the application programming interfaces (APIs) in the Microsoft Dynamics 365 Commerce online software development kit (SDK) that are used to set and get cookie data.

Cookie consent

Before cookies can be stored, the user must give consent. The Dynamics 365 Commerce online SDK provides utilities that help guarantee that the read/write operation of a cookie depends on user consent.

Cookie APIs

The Dynamics 365 Commerce online SDK provides a set of APIs that access cookies from within the props.context.request.cookies API, as shown in the following interface.

export interface ICookieContext {
    get<T>(cookieName: string): ICookieValue<T>;
    set<T>(cookieName: string, cookieValue: T, options?: ICookieSetOptions): void;
    getCartCookie(): string;
    setCartCookie(cart: Cart, isAuthenticated: boolean): void;
    getCheckoutCartCookie(): string;
    setCheckoutCartCookie(cart: Cart, isAuthenticated: boolean): void;
    removeCheckoutCartCookie(): void;
    remove(cookieName: string): void;
    isConsentGiven(): boolean;
    setConsentCookie(): void;
    deleteConsentCookie(): void;
    getTargetIdCookie(): string;
}

Obtain user consent

The setConsentCookie() API is used to obtain user consent before cookies can be written.

Determine whether user consent has been given

The isConsentGiven() API is used to determine whether user consent has been given.

Set a cookie

The following example shows how to set a cookie.

this.props.context.request.cookies.set<string>('favoriteColor', 'blue');

If user consent isn't given before this API is called, the SDK maintains a queue of all set operations and sets a cookie only after the user gives consent.

Get the value of a cookie

The following example shows how to get the value of a cookie.

const favColor = this.props.context.request.cookies.get<string>('favoriteColor');

Additional resources

Request properties object

App settings

Platform settings file

Extend a module definition file

Interactive components overview

Mock the signed-in state during local development

Configure module properties to be shown based on context

Globalize modules by using the CultureInfoFormatter class

Set up Azure Key Vault for secure key management

[!INCLUDEfooter-include]