Skip to content
Magento2 Node.js Rest client
JavaScript
Branch: master
Clone or download
pkarw Merge pull request #18 from rain2o/update/orders-history
Change orderHistory to pull by customer_id
Latest commit 29cfac4 Oct 14, 2019

README.md

Magento2 REST client

This Node.js library enables JavaScript applications to communicate with Magento2 sites using their REST API. This module based on the magento2-rest-client module created by Marko Novak (2016).

This module is used by the Vue Storefront - first Progressive Web App for eCommerce.

NOTE: the library is not finished yet! Only a subset of Magento2 API is currently implemented.

Installation

The library can be installed using the Npm package manager:

    npm install --save github:DivanteLtd/magento2-rest-client

Usage

The code sample below shows the usage of the library:

    var Magento2Client = require('magento2-rest-client').Magento2Client;

    var options = {
          'url': 'http://www.test.com/index.php/rest',
          'consumerKey': '<OAuth 1.0a consumer key>',
          'consumerSecret': '<OAuth 1.0a consumer secret>',
          'accessToken': '<OAuth 1.0a access token>',
          'accessTokenSecret': '<OAuth 1.0a access token secret>'
    };
    var client = Magento2Client(options);
    client.categories.list()
        .then(function (categories) {
            assert.equal(categories.parentId, 1);
        })

You can extend the API by adding Your own modules or adding methods to the existing modules!

    var Magento2Client = require('magento2-rest-client').Magento2Client;

    var options = {
          'url': 'http://www.test.com/index.php/rest',
          'consumerKey': '<OAuth 1.0a consumer key>',
          'consumerSecret': '<OAuth 1.0a consumer secret>',
          'accessToken': '<OAuth 1.0a access token>',
          'accessTokenSecret': '<OAuth 1.0a access token secret>'
    };
    var client = Magento2Client(options);

    client.addMethods('categories', function (restClient) {
            var module = {};
            module.listEx = function () {
                return restClient.get('/categories');
            }
            return module;
        }
    )

    client.addMethods('newModule', function (restClient) {
            var module = {};
            module.newMethod = function () {
                return restClient.post('/custom_magento_api_endpoint');
            }
            return module;
        }
    )

    client.categories.listEx()
        .then(function (categories) {
            assert.equal(categories.parentId, 1);
        })
    client.newModule.newMethod()
        .then(function (resultJson) {
        })

Contributing

usefull resources

Magento API with Swagger: https://devdocs.magento.com/swagger/

Entry Page of REST API Documentation of Magento: https://devdocs.magento.com/guides/v2.3/rest/bk-rest.html filter response: https://devdocs.magento.com/guides/v2.3/rest/retrieve-filtered-responses.html

You can’t perform that action at this time.