Registry / crm-productivity / shopify-api-node

shopify-api-node

JSON →
library3.15.0jsnpmunverified

The `shopify-api-node` package provides robust and well-maintained bindings for interacting with the Shopify REST and GraphQL APIs from Node.js environments. Currently stable at version 3.15.0, the library receives regular updates to maintain compatibility with new Shopify API versions and features, ensuring developers have access to the latest functionalities. Key differentiators include built-in automatic rate limiting (configurable via `autoLimit`) to manage API call quotas, comprehensive proxy support through the `agent` option utilizing `got`, and the flexibility to customize JSON parsing and stringification functions for handling specific data types like long integer IDs. It supports both private app credentials (API key and password) and public app OAuth access tokens, making it versatile for various Shopify application architectures.

npm install shopify-api-node
INSTALL
IMPORT
SIG · SHOPIFY-API-NODE
S
shopify-api-node
crm-productivityjavascriptv3.15.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Shopify
import Shopify from 'shopify-api-node';
const Shopify = require('shopify-api-node');
The library primarily exports a default constructor function. While `require` works for CommonJS, `import` is preferred for modern Node.js ESM projects.
Options
import type { Options } from 'shopify-api-node';
Type import for the configuration object passed to the Shopify constructor, useful for TypeScript projects.
ShopifyRestResources
import type { ShopifyRestResources } from 'shopify-api-node';
This type provides interfaces for the available REST API resources and methods, enhancing type safety when interacting with different API endpoints.

Initializes the Shopify client, fetches a list of products, and then retrieves a single product by ID, demonstrating basic API interaction with environment variables for credentials.

import Shopify from 'shopify-api-node'; const shopify = new Shopify({ shopName: process.env.SHOPIFY_SHOP_NAME ?? 'my-shop-name', accessToken: process.env.SHOPIFY_ACCESS_TOKEN ?? 'shpca_YOUR_ACCESS_TOKEN', // Alternatively for private apps: // apiKey: process.env.SHOPIFY_API_KEY ?? 'YOUR_API_KEY', // password: process.env.SHOPIFY_PASSWORD ?? 'YOUR_PASSWORD', apiVersion: '2024-04', // Always specify a stable API version autoLimit: true // Enable automatic rate limiting }); async function getProducts() { try { const products = await shopify.product.list({ limit: 5, fields: 'id,title,variants' }); console.log('Fetched products:', JSON.stringify(products, null, 2)); // Example: Fetch a specific product by ID if (products.length > 0) { const firstProductId = products[0].id; const singleProduct = await shopify.product.get(firstProductId); console.log('Fetched single product:', singleProduct.title); } } catch (error) { console.error('Error fetching products:', error); if (error.response && error.response.statusCode) { console.error('Shopify API Error Status:', error.response.statusCode); console.error('Shopify API Error Body:', error.response.body); } } } getProducts();
Debug
Known issues
gotchaThe `apiKey` and `password` options are strictly for private (custom) apps and are mutually exclusive with the `accessToken` option used for public (OAuth) apps. Attempting to use both sets will result in an initialization error.
fix
Ensure you provide either `apiKey` and `password` (for private apps) OR `accessToken` (for public apps), but never both simultaneously.
affects: >=1.0.0
gotchaThe `autoLimit` and `maxRetries` options are mutually exclusive. `autoLimit` implements a token bucket algorithm to prevent hitting rate limits proactively, while `maxRetries` handles retries reactively after a rate limit error or other transient network issues. Choose one strategy.
fix
Set either `autoLimit` to `true` (or an object configuration) or `maxRetries` to a number greater than 0, but do not enable both at the same time.
affects: >=1.0.0
gotchaAlways specify the `apiVersion` explicitly (e.g., '2024-04') to ensure your application relies on a stable and predictable API version. If omitted, the library defaults to the oldest supported stable version, which might not align with your application's expected features or behavior.
fix
Include `apiVersion: 'YYYY-MM'` in the `Shopify` constructor options, regularly updating it as Shopify releases new stable API versions.
affects: >=1.0.0
gotchaShopify uses 64-bit integer IDs, which can exceed JavaScript's `Number.MAX_SAFE_INTEGER`. While the library generally handles this, custom JSON parsing (`parseJson` option) might be needed if you encounter precision issues when dealing with large IDs, especially in specific browser or serialization contexts.
fix
If precision issues with large IDs occur, provide a custom `parseJson` function that handles big integers, for example, by parsing them as strings or using a `BigInt` polyfill/library.
affects: >=1.0.0
Errors
Common errors & fixes
Error: "shopName" is required.
The `shopName` option, representing your Shopify store's URL (e.g., 'my-shop.myshopify.com'), was omitted during client initialization.
fix
Provide a `shopName` string in the `Shopify` constructor options, like `new Shopify({ shopName: 'my-shop.myshopify.com', ... })`.
Error: Options "apiKey" and "password" are mutually exclusive with option "accessToken".
Attempted to initialize the Shopify client with both private app credentials (`apiKey`, `password`) and a public app access token (`accessToken`) simultaneously.
fix
Choose one authentication method: either provide `apiKey` and `password` for private apps OR `accessToken` for public/custom apps that use OAuth.
ReferenceError: Shopify is not defined (or similar import error in ESM)
Incorrect import statement for `Shopify` in an ESM project, often trying to use `require()` or an incorrect named import.
fix
For ESM, use `import Shopify from 'shopify-api-node';`. Ensure your `package.json` specifies `"type": "module"` or files end with `.mjs`.
HTTP 429 Too Many Requests
Your application has exceeded Shopify's API rate limits. This can happen if `autoLimit` is disabled or not configured effectively for high-volume operations.
fix
Enable `autoLimit: true` in your Shopify client options, or configure it with specific `calls`, `interval`, and `bucketSize` settings. Consider using `maxRetries` if `autoLimit` is not desired for proactive limiting.
Upgrade
Version history
3.15.0latest on npm
Audit
Dependencies
gotrequiredCore HTTP client for making requests; mentioned in options for `agent` and `hooks`.
Agent activity
31 hits · last 30 days
node
26
Resources
shopify-api-node — npm install shopify-api-node · libregistry