Skip to content

vuestorefront/magento2-rest-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magento2 REST client

Stay connected

GitHub Repo stars Twitter Follow YouTube Channel Subscribers Discord

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

Credit

This Repository is an independent fork of https://github.com/nouvak/magento2-rest-client created by Marko Novak.

About

Magento2 Node.js Rest client

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published