Catalyst allows you to retrieve info from BigCommerce’s APIs through the Catalyst Client.
The client simplifies what you need to do to handle requests and responses. For example, you don’t need to construct request URLs, configure request headers, or parse JSON responses. The client uses the channel ID and authorization tokens configured in the .env file by default.
fetch(): allows you to interact with BigCommerce’s GraphQL Storefront API. You can execute all queries and mutations available in BigCommerce’s Storefront graph.
fetchSitemapIndex(channelId?: string): fetches the sitemap index for the store, which provides a URL to the XML sitemap.
The following sections describe the fetch() method.
The fetch method automatically sets the following headers:
"Content-Type": "application/json""User-Agent": <backendUserAgent>"X-Bc-Customer-Access-Token": <customerAccessToken> (when customerAccessToken is provided)"X-Bc-Error-On-Invalid-Customer-Access-Token": <validateCustomerAccessToken> (when validateCustomerAccessToken is true)The fetch method returns a promise that resolves to a response object containing the requested data. The response follows the structure defined in the GraphQL query.
Return Type: Promise<BigCommerceResponse<TResult>>
The BigCommerceResponse type wraps the actual data returned from the API, where TResult represents the expected shape of the response data.
Inside BigCommerceResponse, the data field holds the actual data returned by the GraphQL API, which matches the structure of the query or mutation you executed.
Error Handling:
If the response is not ok (i.e., the request fails), the method throws a BigCommerceAPIError, which includes the HTTP status and any GraphQL errors returned in the response.
The example output in the console:
The BigCommerceAPIError class provides error handling and is instantiated when the fetch fails.
You can log the request’s operation name, type, and execution time to the console, along with the query complexity.
To use this feature, enable logging through the CLIENT_LOGGER environment variable. When you run the fetch method, it will invoke the requestLogger() function internally to capture and log the information.