magento2-api-wrapper

Basic wrapper for Magento 2 API using Axios


Keywords
magento2, api, ecommerce, node, javascript, axios, nodejs
License
MIT
Install
npm install magento2-api-wrapper@1.5.1

Documentation

Magento2 API Wrapper

License: MIT NPM Dependencies Builds Coverage

A basic wrapper for Magento 2 API

Install

npm install magento2-api-wrapper

Usage

const Magento2Api = require('magento2-api-wrapper')

var consumer = new Magento2Api({ api: { url: 'https://localhost' }})

consumer.get('directory/countries')
  .then(data => console.log)

// Api Keys: Magento Admin > System > Extensions > Integration
var admin = new Magento2Api({ api: {
  url: 'https://localhost',
  consumerKey: 'xxx',
  consumerSecret: 'xxx',
  accessToken: 'xxx',
  tokenSecret: 'xxx',
}})

admin.get('products', {
  params: {
    searchCriteria: {
      currentPage: 1,
      pageSize: 1,
    }
  }
})
  .then(data => console.log)

Responses: Successfull response returns data as in Magento - not wrapped as in Axios.

Methods / Properties

It provides all same methods as Axios: https://github.com/axios/axios#request-method-aliases (request, get, delete, head, options, post, put, patch)

  • .axios - get axios instance
  • .baseUrl - get base url

Run tests

npm run test