JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 196
  • Score
    100M100P100Q83936F
  • License MIT

Basic wrapper for Magento 2 API using Axios

Package Exports

  • magento2-api-wrapper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (magento2-api-wrapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Magento2 API Wrapper

License: MIT NPM Dependencies Builds Coverage

A basic wrapper for Magento 2 API

Currently only works in Node environment. But, it should be easy to make it compatible in browsers. Feel free to submit a merge request or contact me.

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