Alokai

getShippingMethods

Fetch shipping methods.

In turn, it fetches a shipping methods from commercetools by sending a request to its GraphQL API.

By default, it uses the getProductDefaultQuery GraphQL query

Signature

declare function getShippingMethods(
	context: CommercetoolsIntegrationContext,
	cartId?: string,
	customQuery?: CustomQuery
): Promise<GetShippingMethodsResponse>;

Parameters

NameRequiredTypeDescription
contextRequiredCommercetoolsIntegrationContext
cartIdOptionalstring
customQueryOptionalCustomQuery

Returns

Returns a representation of the GetShippingMethodsResponse.

Referenced Types

Examples

Fetching shipping methods for the cart.

const { shippingMethods } = await sdk.commerce.getShippingMethods({
  cartId: 'f8941d7d-5af9-4ca0-ad4a-c9d11adeedc3'
});

Creating a custom GraphQL query for shipping methods.

export const integrations = {
    ct: {
      // ...
      customQueries: {
        'get-shipping-methods-custom-query': ({ variables, metadata }) => {
          return {
            variables,
            query: `
              query shippingMethods($acceptLanguage: [Locale!], $cartId: String!) {
                shippingMethods: shippingMethodsByCart(id: $cartId) {
                  ${metadata}
                }
            }
           `
          }
        }
      };
    }
  }
};

Fetching shipping methods and using the customQuery parameter to leverage the custom GraphQL query from the previous example.

const { shippingMethods } = await sdk.commerce.getShippingMethods({
  cartId: 'f8941d7d-5af9-4ca0-ad4a-c9d11adeedc3'
}, {
  shippingMethods: 'get-shipping-methods-custom-query',
  metadata: `
    id
    name
    isDefault
    localizedDescription(acceptLanguage: $acceptLanguage)
  `
});

On this page