Magento API REST (Legacy)
A Node.js client wrapper to work with the Magento 1.X REST API.
Installation
npm i magento-api-rest-legacy
Getting started
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
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>'
});
Options
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 |
Methods
GET
.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
Params | Type | Description |
---|
endpoint | String | Magento API endpoint, example: shipments |
data | Object | JSON object to be sent as body. |
PUT
Params | Type | Description |
---|
endpoint | String | Magento API endpoint, example: shipments/12 |
data | Object | JSON object to be sent as body. |
DELETE
Params | Type | Description |
---|
endpoint | String | Magento API endpoint, example: orders/12 |
data | Object | JSON object to be sent as body. |
API
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",
"limit": 100
}
If you want to use the above object in a request,
async function getOrders () {
try {
let response = await client.get('orders', params);
} catch (error) {
}
}