Alokai

getShoppingList

Get user's shopping lists.

It fetches a list of shopping lists from commercetools by sending a request to its GraphQL API. By default, it uses the getShoppingListDefaultQuery GraphQL query

By default the method fetches a single, most recent wishlist belonging to a particular guest or a customer. Refer to the examples section to learn how to modify this behaviour.

The method can also be accessed with the getMyShoppingList alias.

Signature

declare function getShoppingList(
	context: CommercetoolsIntegrationContext,
	params?: GetShoppingListParams,
	customQuery?: CustomQuery
): Promise<GetShoppingListResponse>;

Parameters

NameRequiredTypeDescription
contextRequiredCommercetoolsIntegrationContext
paramsOptionalGetShoppingListParams
customQueryOptionalCustomQuery

Returns

Returns a representation of the GetShoppingListResponse.

Referenced Types

Examples

Fetching the most recently created shopping list.

const { me: { shoppingLists } } = await sdk.commerce.getShoppingList();

Fetching a list of max 5 shopping lists sorted by name in ascending order. Learn more about sorting in commercetools https://docs.commercetools.com/api/general-concepts#sorting

const { me: { shoppingLists } } = await sdk.commerce.getShoppingList({
  limit: 5,
  sort: ['name.en asc']
});

Fetching a shopping list using the where parameter. Learn more about building query predicates in commercetools https://docs.commercetools.com/api/predicates/query

const { me: { shoppingLists } } = await sdk.commerce.getShoppingList({
  where: 'name(en="wishlist")'
});

Fetching a shopping list using the id convenience parameter. It only has an effect when the where parameter is not defined.

const { me: { shoppingLists } } = await sdk.commerce.getShoppingList({
  id: '793e8642-7517-4af9-9431-3e29b6206e10'
});

Creating a custom GraphQL query for fetching user's shopping list in middleware.config.ts.

export const integrations: {
    ct: {
      // ...
      customQueries: {
       'get-shopping-list-custom-query': ({ query, variables, metadata }) => ({
         variables: Object.assign(variables, metadata?.variables),
         query: `
           query getMe(
             $where: String,
             $sort: [String!],
             $limit: Int,
             $offset: Int
           ) {
             me {
               shoppingLists(
                 where: $where,
                 sort: $sort,
                 limit: $limit,
                 offset: $offset
               ) {
                 results {
                   ${metadata?.fields}
                 }
               }
             }
           }
         `
       }),
      }
    }
  }
};

Fetching the most recently created shopping list and selecting response fields using the custom GraphQL query from the previous example.

const { me } = await sdk.commerce.getShoppingList(
  null,
  {
    getMe: 'get-shopping-list-custom-query',
    metadata: 'id,version'
  }
);

On this page