0.0.4 • Published 3 years ago

magento-api-rest-legacy v0.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

Magento API REST (Legacy)

A Node.js client wrapper to work with the Magento 1.X REST API.

npm version dependencies Status

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

OptionTypeRequiredDescription
urlStringyesYour Store URL
consumerKeyStringyesYour API consumer key
consumerSecretStringyesYour API consumer secret
accessTokenStringyesYour API Access Token
tokenSecretStringyesYour API Access Token Secret
timeoutNumbernoRequest Timeout
axiosConfigObjectnoReference

Methods

GET

  • .get(endpoint)
  • .get(endpoint, params)
ParamsTypeDescription
endpointStringMagento API endpoint, example: orders
paramsObjectJSON 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

  • .post(endpoint, data)
ParamsTypeDescription
endpointStringMagento API endpoint, example: shipments
dataObjectJSON object to be sent as body.

PUT

  • .put(endpoint, data)
ParamsTypeDescription
endpointStringMagento API endpoint, example: shipments/12
dataObjectJSON object to be sent as body.

DELETE

  • .delete(endpoint, data)
ParamsTypeDescription
endpointStringMagento API endpoint, example: orders/12
dataObjectJSON 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", // 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
    }
}