Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Magento
✓ import Magento from 'magento-api-rest'
✗ const Magento = require('magento-api-rest')
ESM default import works in TypeScript and modern Node. CommonJS users must use require('magento-api-rest').default.
Magento (default export)
✓ const Magento = require('magento-api-rest').default
✗ const Magento = require('magento-api-rest')
In CommonJS, the module exports an object with a 'default' property containing the class.
MagentoConfig
✓ import type { MagentoConfig } from 'magento-api-rest'
✗ import { MagentoConfig } from 'magento-api-rest'
MagentoConfig is a TypeScript type available via import type. Not exported at runtime.
Shows how to instantiate the Magento client with OAuth credentials and make a GET request to fetch orders.
import Magento from 'magento-api-rest';
const client = new Magento({
url: process.env.MAGENTO_URL ?? 'https://magento.example.com',
consumerKey: process.env.MAGENTO_CONSUMER_KEY ?? '',
consumerSecret: process.env.MAGENTO_CONSUMER_SECRET ?? '',
accessToken: process.env.MAGENTO_ACCESS_TOKEN ?? '',
tokenSecret: process.env.MAGENTO_TOKEN_SECRET ?? '',
});
async function getOrders() {
try {
const orders = await client.get('orders', { searchCriteria: { pageSize: 10 } });
console.log(orders);
} catch (err) {
console.error('Error fetching orders:', err);
}
}
getOrders();
Errors
Common errors & fixes
TypeError: Magento is not a constructor
In CommonJS, the import returns an object with a 'default' property, not the class directly.
fixUse const Magento = require('magento-api-rest').default; Cannot find module 'magento-api-rest'
Package not installed or wrong import path.
fixRun npm install magento-api-rest and ensure the import is correct.
Error: Request failed with status code 401
Invalid or missing OAuth credentials, or incorrect endpoint type.
fixVerify OAuth credentials and ensure the 'type' option matches the intended endpoint.
Audit
Dependencies
axiosrequiredHTTP client for making REST requests
oauth-1.0arequiredOAuth 1.0a signature generation