A Node.js client wrapper to work with the Magento 1.X REST API.
npm i magento-api-rest-legacy
Generate API credentials by following these instructions.
Make sure to check the resource access is as per your requirements to prevent misuse of the API Keys.
- This library is compatible only with Magento 1.X REST Endpoints for Magento 2.X based stores, use the sister package.
Setup for the Magento REST API integration:
const MagentoAPI = require('magento-api-rest-legacy');
const client = new MagentoAPI({
'url': 'http://www.your-store.dev',
'consumerKey': '<OAuth 1.0a consumer key>',
'consumerSecret': '<OAuth 1.0a consumer secret>',
'accessToken': '<OAuth 1.0a access token>',
'tokenSecret': '<OAuth 1.0a access token secret>'
});
Option | Type | Required | Description |
---|---|---|---|
url |
String |
yes | Your Store URL |
consumerKey |
String |
yes | Your API consumer key |
consumerSecret |
String |
yes | Your API consumer secret |
accessToken |
String |
yes | Your API Access Token |
tokenSecret |
String |
yes | Your API Access Token Secret |
timeout |
Number |
no | Request Timeout |
axiosConfig |
Object |
no | Reference |
.get(endpoint)
.get(endpoint, params)
Params | Type | Description |
---|---|---|
endpoint |
String |
Magento API endpoint, example: orders |
params |
Object |
JSON object to be sent as params. |
- Note: In case no params are specified or required, you can leave params as empty. That will result in "?searchCriteria=all" in the URL.
.post(endpoint, data)
Params | Type | Description |
---|---|---|
endpoint |
String |
Magento API endpoint, example: shipments |
data |
Object |
JSON object to be sent as body. |
.put(endpoint, data)
Params | Type | Description |
---|---|---|
endpoint |
String |
Magento API endpoint, example: shipments/12 |
data |
Object |
JSON object to be sent as body. |
.delete(endpoint, data)
Params | Type | Description |
---|---|---|
endpoint |
String |
Magento API endpoint, example: orders/12 |
data |
Object |
JSON object to be sent as body. |
Requests are made with Axios library with support to promises.
let params = {
"filter": [
{
"attribute": "entity_id",
"neq": 3,
"in": [1,2,3],
"nin": [1,2,3],
"gt": 3,
"lt": 3,
"from": "Date",
"to": "Date"
}
],
"page": 1,
"order": "name",
"dir": "dsc", // Or asc
"limit": 100
}
If you want to use the above object in a request,
async function getOrders () {
try {
let response = await client.get('orders', params);
// Response Handling
} catch (error) {
// Error Handling
}
}