GithubHelp home page GithubHelp logo

ajsb85 / node-magento-rest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from desmondmorris/node-twitter

3.0 2.0 1.0 284 KB

An asynchronous client library for the Magento REST API.

Home Page: https://www.npmjs.com/package/magento-rest

JavaScript 92.26% Shell 7.74%

node-magento-rest's Introduction

Magento for Node.js

An asynchronous client library for the Magento REST API.

wercker status NPM

var Magento = require('magento-rest');

var client = new Magento({
  consumer_key: '',
  consumer_secret: '',
  access_token_key: '',
  access_token_secret: ''
});

var params = {screen_name: 'nodejs'};
client.get('statuses/user_timeline', params, function(error, products, response){
  if (!error) {
    console.log(products);
  }
});

Installation

npm install Magento

Quick Start

You will need valid Magento developer credentials in the form of a set of consumer and access tokens/keys. You can get these here. Do not forgot to adjust your permissions - most POST request require write permissions.

var Magento = require('magento-rest');

For User based authetication:

var client = new Magento({
  consumer_key: '',
  consumer_secret: '',
  access_token_key: '',
  access_token_secret: ''
});

Add your credentials accordingly. I would use environment variables to keep your private info safe. So something like:

var client = new Magento({
  consumer_key: process.env.MAGENTO_CONSUMER_KEY,
  consumer_secret: process.env.MAGENTO_CONSUMER_SECRET,
  access_token_key: process.env.MAGENTO_ACCESS_TOKEN_KEY,
  access_token_secret: process.env.MAGENTO_ACCESS_TOKEN_SECRET,
});

For Application Only based authetication:

You will need to fetch a bearer token from Magento as documented Here, once you have it you can use it as follows.

var client = new Magento({
  consumer_key: '',
  consumer_secret: '',
  bearer_token: ''
});

Add your credentials accordingly. I would use environment variables to keep your private info safe. So something like:

var client = new Magento({
  consumer_key: process.env.MAGENTO_CONSUMER_KEY,
  consumer_secret: process.env.MAGENTO_CONSUMER_SECRET,
  bearer_token: process.env.MAGENTO_BEARER_TOKEN,
});

NB - You will not have access to all endpoints whilst using Application Only authentication, but you will have access to higher API limits.

Requests

You now have the ability to make GET and POST requests against the API via the convenience methods.

client.get(path, params, callback);
client.post(path, params, callback);
client.stream(path, params, callback);

REST API

You simply need to pass the endpoint and parameters to one of convenience methods. Take a look at the documentation site to reference available endpoints.

Example, lets get a list of favorites:

client.get('favorites/list', function(error, products, response){
  if(error) throw error;
  console.log(products);  // The favorites.
  console.log(response);  // Raw response object.
});

How about an example that passes parameters? Let's tweet something:

client.post('statuses/update', {status: 'I Love Magento'},  function(error, tweet, response){
  if(error) throw error;
  console.log(tweet);  // Tweet body.
  console.log(response);  // Raw response object.
});

Streaming API

Using the stream convenience method, you to open and manipulate data via a stream piped directly from one of the streaming API's. Let's see who is talking about javascript:

client.stream('statuses/filter', {track: 'javascript'}, function(stream) {
  stream.on('data', function(tweet) {
    console.log(tweet.text);
  });

  stream.on('error', function(error) {
    throw error;
  });
});

Examples

Contributors

Maintained by @ajsb85

Based on Twitter, authored by @technoweenie and maintained by @jdub

Twitter is currently maintained by @desmondmorris

And we cannot forget the community

LICENSE

magento-rest: Copyright (c) 2016 Alexander J. Salas B.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node-magento-rest's People

Contributors

jdub avatar desmondmorris avatar technoweenie avatar tim-smart avatar jmalonzo avatar oesmith avatar alaaattya avatar sergiocrisostomo avatar gazzer82 avatar haruair avatar miql avatar julien-c avatar secos avatar mulderp avatar romaintb avatar roncli avatar ryantenney avatar chrisweb avatar gnomus avatar k0t0fey avatar hyl avatar qix- avatar hughrawlinson avatar hectorlee avatar francois2metz avatar ptmt avatar iclems avatar christopherwright avatar ajsb85 avatar

Stargazers

Ismael IC avatar Alfred Lau avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

krolcom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.