Package Exports
- @ns8/magento2-rest-client
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 (@ns8/magento2-rest-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 @ns8/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