js-magento-client

1.0.3 • Public • Published

js-magento-client

Magento javascript client for node.js using ES6 class

install

npm install js-magento-client

Usage

Login Api

import {MagentoAccountApi} from 'js-magento-client';
import expect from 'expect';
 
let url = 'magento-url';
let username = 'username';
let password = 'password';
 
MagentoAccountApi.loginAsClient(
      url, 
      username, 
      password)
      .then((response) => {
        let token = response.data;
        expect(response.status).toEqual(200);
        expect(token.length).toBeGreaterThan(0);
        done();
      }).catch(reason => {
        console.log(reason);
        done(new Error(reason));
      });

Root Category Api

import {MagentoCategoryApi} from 'js-magento-client';
import expect from 'expect';
 
let url = 'magento-url';
 
MagentoCategoryApi.loadRootCategory(url).then(response => {
   let rootCategory = response.data;
   expect(rootCategory.children_data.length).toBeGreaterThan(0);
   done();
}).catch(reason => {
   console.log(reason);
   done(new Error(reason));
});

Load Products in a particular category

import {MagentoCategoryApi} from 'js-magento-client';
import expect from 'expect';
 
let categoryId = 19;
let url = 'magento-url';
 
MagentoCategoryApi.loadProducts(url, categoryId).then(response => {
   //console.log(response.data);
   expect(response.data.length).toBeGreaterThan(0);
   done();
}).catch(reason => {
   console.log(reason);
   done(new Error(reason));
})

Load Product by SKU

import {MagentoProductApi} from 'js-magento-client';
import expect from 'expect';
 
let sku = 'product_dynamic_17';
let url = 'magento-url';
 
MagentoProductApi.loadProduct(url, sku).then(response => {
   let product = response.data;
   console.log(product);
   done();
}).catch(reason => {
   console.log(reason);
   done(new Error(reason));
});

Package Sidebar

Install

npm i js-magento-client

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • chen0040