Alokai
You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current

createMyShoppingList

Method for creating new Shopping List.

This method sends a POST request to the createMyShoppingList endpoint. and adds a product to the Shopping List.

Signature

export declare function createMyShoppingList<Res extends PartialCreateMyShoppingListResponse = CreateMyShoppingListResponse>(
	params: CreateMyShoppingListParams,
	options?: MethodOptions<CustomQuery<"createMyShoppingList">>
): Promise<Res>;

Parameters

NameRequiredTypeDescription
paramsRequiredCreateMyShoppingListParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodOptions<CustomQuery<"createMyShoppingList">>Options that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of the CreateMyShoppingListResponse.

Referenced Types

Examples

Adding a product to the Shopping List:

const MY_SHOPPING_LIST_PARAMS = {
  name: [
    { locale: 'en', value: 'en-test' },
  ],
  description: [
    { locale: 'en', value: 'en-test-description' }
  ],
  lineItems: [
    {
      sku: 'some-sku',
      quantity: 1
    }
  ]
};

const { wishlist } = await sdk.commerce.createMyShoppingList(MY_SHOPPING_LIST_PARAMS);

Creating a custom GraphQL query for the method in middleware.config.js:

module.exports = {
  integrations: {
    ct: {
      // ...
      customQueries: {
        'create-my-shopping-list-custom-query': ({ variables, metadata }) => {
           return {
             variables,
               query: `
               mutation createMyShoppingList($draft: MyShoppingListDraft!) {
               wishlist: createMyShoppingList(draft: $draft) {
                 ${metadata}
               }
             }`
           };
         }
       }
     }
   }
};

Using a custom GraphQL query for the method: customQuery parameter to leverage the custom GraphQL query from the previous example.

import { sdk } from '~/sdk.config.ts';

const customQuery = {
  createMyShoppingList: 'create-my-shopping-list-custom-query',
  metadata: 'id version lineItems { id quantity }'
};

type MyResponseType = {
  wishlist: {
    id: string;
    version: number;
    lineItems: Array<{
      id: string;
      quantity: number;
    }>
  }
}

 const { wishlist } = await sdk.commerce.createMyShoppingList<MyResponseType>(MY_SHOPPING_LIST_PARAMS, { customQuery });

On this page