Skip to main content
Glama

get_all_products

Retrieve all products from a BigCommerce store using API integration. Store hash can be provided or automatically sourced from environment variables for product management.

Instructions

Get all products from the BigCommerce API. Store hash is automatically retrieved from environment variables.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
store_HashNoOptional store hash. If not provided, uses BIGCOMMERCE_STORE_HASH from environment variables.

Implementation Reference

  • The `executeFunction` implements the core logic to fetch all products from the BigCommerce v3 catalog API endpoint using fetch, with error handling, empty response handling, and JSON parsing.
    const executeFunction = async ({ store_Hash } = {}) => { const baseUrl = 'https://api.bigcommerce.com/stores'; const apiKey = process.env.BIGCOMMERCE_API_KEY; // Use provided store hash or default from environment const storeHash = store_Hash || process.env.BIGCOMMERCE_STORE_HASH; try { // Construct the URL for the request const url = `${baseUrl}/${storeHash}/v3/catalog/products`; // Set up headers for the request (matching n8n configuration) const headers = { 'X-Auth-Token': apiKey, 'Content-Type': 'application/json', 'Accept': 'application/json' }; // Perform the fetch request const response = await fetch(url, { method: 'GET', headers }); // Check if the response was successful if (!response.ok) { let errorData; try { errorData = await response.json(); } catch (e) { // If JSON parsing fails, use the text response const errorText = await response.text(); throw new Error(`HTTP ${response.status}: ${errorText || response.statusText}`); } throw new Error(JSON.stringify(errorData)); } // Get response text first to handle empty responses const responseText = await response.text(); // Check if response is empty if (!responseText || responseText.trim() === '') { return { data: [], meta: { total: 0 } }; } // Parse and return the response data try { const data = JSON.parse(responseText); return data; } catch (parseError) { throw new Error(`Invalid JSON response: ${responseText.substring(0, 200)}...`); } } catch (error) { console.error('Error getting all products:', error); return { error: `An error occurred while getting all products: ${error instanceof Error ? error.message : JSON.stringify(error)}` }; } };
  • The tool schema definition, including name, description, and input parameters schema (store_Hash optional string).
    type: 'function', function: { name: 'get_all_products', description: 'Get all products from the BigCommerce API. Store hash is automatically retrieved from environment variables.', parameters: { type: 'object', properties: { store_Hash: { type: 'string', description: 'Optional store hash. If not provided, uses BIGCOMMERCE_STORE_HASH from environment variables.' } }, required: [] } } }
  • The `apiTool` object that binds the handler function to its schema definition and exports it for registration in the MCP server via discoverTools.
    const apiTool = { function: executeFunction, definition: { type: 'function', function: { name: 'get_all_products', description: 'Get all products from the BigCommerce API. Store hash is automatically retrieved from environment variables.', parameters: { type: 'object', properties: { store_Hash: { type: 'string', description: 'Optional store hash. If not provided, uses BIGCOMMERCE_STORE_HASH from environment variables.' } }, required: [] } } } }; export { apiTool };
  • The `discoverTools` function dynamically imports all apiTool exports from tool paths (including get-all-products.js) and prepares them for MCP server registration, handling name deduplication.
    export async function discoverTools() { const tools = await Promise.all( toolPaths.map(async (file) => { const { apiTool } = await import(`../tools/${file}`); return { ...apiTool, path: file }; }) ); // deduplicate tool names const nameCounts = {}; return tools.map((tool) => { const name = tool.definition?.function?.name; if (!name) return tool; nameCounts[name] = (nameCounts[name] || 0) + 1; if (nameCounts[name] > 1) { tool.definition.function.name = `${name}_${nameCounts[name]}`; } return tool; }); }
  • The `toolPaths` array registers the file path for the get_all_products tool, used by discoverTools to load it.
    export const toolPaths = [ 'bigcommerce/res-tful-api-basics-blueprint/get-all-products.js', 'bigcommerce/res-tful-api-basics-blueprint/get-all-customers.js', 'bigcommerce/res-tful-api-basics-blueprint/get-all-orders.js' ];

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/isaacgounton/bigcommerce-api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server