BigCommerce – Catalog API and GraphQL

Catalog API 

The Catalog refers to a store’s collection of physical and digital products. The Catalog includes all the information about a product such as MPN, warranty, price, and images. 

The term “Catalog” refers to the collection of virtual representations of an e-commercemerchant’s saleable products, stored within the BigCommerce platform. The catalog domain also encompasses related functions that augment the ability to communicate product details to shoppers–things like product reviews, bulk pricing, and more. 

The BigCommerce Catalog API manages products, brands, and categories for a store. 

Catalog API is used for POS Integrations,Connect a merchant’s brick-and-mortar POS with their online store to streamline inventory management and reduce overselling. 

Headless commerce –  Pull in products from BigCommerce into an external site Catalog API is necessary. 

Moving Catalog – Moving products from one storeto another 

Filters 

Filters give you the ability to specify what’s included in the response, whether that’s including 

extra properties that are not normally returned or just reducing how many things are returned. 

That overhead will add up as your application scales. 

Includes 

Includes allow you to save API calls by getting more information in a response. However, it may slow down your response. 

Example: – /v3/catalog/products?include=variants,images 

include_fields: – will return the specified fields in the response. 

exclude_fields: – will omit the specified fields from the response. 

Pagination: – ?page is the number of pages that are returned via api. 

Netsuite: – ?limit is the number of results per page that are returned. 

Example:- page=2&limit=10 This will return page 2 of the results with 10 items per page. 

Metadata is additional information that is included on every Catalog API request. 

Example :- “meta”: {  

“pagination”: {  

“total”: 25,  

“count”: 5,  

“per_page”: 5,  

“current_page”: 1,  

“total_pages”: 5,  

“links”: {  

“next”: “?limit=5&page=2”,  

“current”: “?limit=5&page=1”  

},  

“too_many”: false  

}  

}  


 

Create a Variant: – POST request to  

/catalog/products/{product_id}/options 

Example:https://api.bigcommerce.com/stores/{store-hash}/v3/catalog/products/{product_id}/options 

Get all Variant OPtions: – GET 

/catalog/products/{product_id}/options 

Example: – https://api.bigcommerce.com/stores/{store-hash}/v3/ 

catalog/products/{product_id}/variants 

Creates a product variant. 

Example: – https://api.bigcommerce.com/stores/{store- 

hash}/v3/ 

catalog/products/{product_id}/variants 

To see Variants, Variant Options, or Modifier Options on a product, you can send a GETrequest using the v3 API and a Rest client such as Postman to: 

https://api.bigcommerce.com/stores/store-hash/v3/catalog/products/

{productId}/variants 

https://api.bigcommerce.com/stores/store-hash/v3/catalog/products/

{productId}/options 

https://api.bigcommerce.com/stores/store-

hash/v3/catalog/products/{productId}/modifiers. 

More about catalog: – 

https://developer.bigcommerce.com/api-reference/f42984fc9a82c-update-products-batch

                          GraphQL Storefront API 

BigCommerce’s GraphQL Storefront API makes it possible to query storefront data from within a Stencil theme or remote site. This means information previously only available on the back-end using Stencil’s template logic can now be accessed with front-end JavaScript. 

GraphQL API can: – 

  • Access product options, variations, and custom fields for any product from any page. 
  • Request any product’s images at any resolution. 
  • Ask for customer details such as name, email address, and attributes (if logged in). 
  • Look up objects, such as categories or brands, by URL, and fetch their details. 
  • Build front-end applications on top of a BigCommerce Stencil theme or on a remote site. 

To access the GraphQL Storefront API Playground and documentation, sign in to your store and navigate to Settings > API> Storefront API Playground

To use the request runner, input queries on the left side and then click the Play button. Query results will be displayed on the right side. 

Authentication 

The GraphQL API authorizes requests with a bearer token. A bearer token is exposed to Stencil via Handlebars so it is accessible by JavaScript in the theme or Script Manager. 

GraphQL Storefront API requests are authenticated with tokens sent via the HTTP authorizationheader :  

Example: curl ‘https://{bigcommerce_storefront_domain}.com/graphql 

 -H ‘Authorization: Bearer {token}’\  

Creating token 

Use the Create a GraphQL Storefront API token REST endpoint to request JWT-style bearer tokens that authenticate cross-origin requests to the GraphQL Storefront API. 

Example request: Create a GraphQL Storefront API token 

POSThttps://api.bigcommerce.com/stores/{{STORE_HASH}}/v3/storefront/api-token 

X-Auth-Token: {{access_token}} 

Accept: application/json 

Content-Type: application/json 

“channel_id”: 1, // int (must be a valid channel ID on the store) 

“expires_at”: 1602288000, // double utc unix timestamp (required) 

“allowed_cors_origins”: [ // array (accepts 1 origin currently) 

“https://example.com” 

Authenticating with an Auto-Generated Stencil Token Client code in BigCommerce Stencil themes can be passed a token at render time with the {{settings.storefront_api.token}}  

Example: – 

f fetch(‘/graphql’, { 

method: ‘POST’, 

credentials: ‘same-origin’, 

headers: { 

‘Content-Type’: ‘application/json’, 

‘Authorization’: ‘Bearer {{settings.storefront_api.token}}’ 

}, 

body: JSON.stringify({ query: `query MyFirstQuery {…}`}) 

}) 

then(res => console.log(res)) 

catch(error => console.error(error)); 

Note: 

The channel_id for the default Stencil storefront 1 can be passed in for the channel_id for 

generating tokens for use on the default Stencil storefront. 

To create a channel for a remote site, see [Create Channel] in the  API Reference . 

Allowed_cors_origins array accepts only a single origin currently – one token must be generated for each origin. 

/storefront/api-token endpoint requires the Manage Storefront API Tokens OAuth Scope. 

storefront/api-token-customer-impersonation endpoint requires the Manage Storefront 

API Customer Impersonation Tokens OAuth Scope: – 

It’s also possible to generate tokens for use in server-to-server interactions with a trusted consumer using the Create a customer impersonation token endpoint. Consult the endpoint’s documentation to determine what OAuth scopes it requires. 

Customer login: – 

If you’re using the GraphQL Storefront API from a browser, for example, on top of your Stencil storefront, you can use the new Customer Login mutation to sign in to a customer account with an email address and a password. For server-side integrations, consider a customer impersonation token instead. This will set a session cookie in the browser which will authenticate the customer account on future requests 

For reference: – 

https://developer.bigcommerce.com/docs/8138e27e79662-graph-ql-storefront-api-overview

Leave a comment

Your email address will not be published. Required fields are marked *