Alokai

createMyShoppingList

Create new Shopping List.

By default, it uses the createMyShoppingListDefaultQuery GraphQL query

Signature

declare function createMyShoppingList(
	context: CommercetoolsIntegrationContext,
	draft: CreateMyShoppingListParams,
	customQuery?: CustomQuery
): Promise<CreateMyShoppingListResponse>;

Parameters

NameRequiredTypeDescription
contextRequiredCommercetoolsIntegrationContext
draftRequiredCreateMyShoppingListParams
customQueryOptionalCustomQuery

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.ts:

export const 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.

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

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

On this page