adamj88 / node-magento2

6 stars 5 forks source link

Consume Magento 2 REST API

Build Status

Currently a work in progress.

Wrapper for connecting to Magento 2 REST API.

Installation

npm install magento2 --save

Example Usage

This uses restler as a HTTP Client library, please see their documentation for more examples/sample usage.

var Magento2 = require('magento2');

var opt = {
  url: 'http://example.com', // without trailing slash
  username: 'username',
  password: 'password',
  isAdmin: true
};

var magento = new Magento2(opt);

// Create a Token
magento.Api.token = magento.Integration.getToken().on('complete', function(result) {
  if (result instanceof Error) {
    console.log('Error:', result.message);
    this.retry(5000); // try again after 5 sec
  } else {
    return result;
  }
});

// Get Category list
categories = magento.Catalog.getCategories.on('complete', function(result) {
  if (result instanceof Error) {
    console.log('Error:', result.message);
    this.retry(5000); // try again after 5 sec
  } else {
    return result;
  }
});

Options

Option Type Required Description
url String yes Your Store URL, example: http://example.com (without trailing slash)
username String yes Your API username
password String yes Your API password
version Interger no API version, default is 1
encoding String no Encoding, default is 'utf-8'
isAdmin Boolean no Is user admin or customer, default is false (custoemr)

End points

For a complete list of endpoints see:

Those implemented in this module: