npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magento2-rest

v0.11.1

Published

Magento 2 REST API toolset for Node via Axios

Downloads

26

Readme

Magento 2 REST API for Node via Axios

Features

  • Supports both integration access token and admin username / password authentication
  • Includes basic GET/POST/PUT/DELETE http methods
  • Simplified searchCriteria arguments
  • Helpers are included to make it easier to initialize api requests. More helpers will be added to the library.

Initialization

const Magento2 = require('magento2-rest');

// Either login or integration attribute is needed
// Recommend to use integration access token for performance issue
// using admin username and password will have one extra api request to get the integration token
//
Magento2.authentication = {
  login: {
    username:  "YOUR_MAGENTO2_ADMIN_USERNAME",
    password:  "YOUR_MAGENTO2_ADMIN_PASSWORD"
  },
  integration: {
    access_token:"ACCESS_TOKEN_FROM_INTEGRATION_ADMIN_SECTION"
  }
}

// Your magento2 store url + '/rest/V1'
//
Magento2.storeRestUrl = "YOUR_MAGENTO_STORE_REST_URL";

// Initialize Helpers - It is not required if helper is not used
//
Magento2.initHelpers();

How to Use

Examples on basic usage without helpers

// Basic GET examples on products
//
// options are the search criteria parameters
// Possible attributes: `filter`, `sort`, `pageSize`, `currentPage`, `projection`
// 
// Options examples:
// - filter: [{ field: "name", value: "hello", condition_type: "like" }, { field: "id", value: "5", condition_type: "eq" }]
// - sort: { name: 1, id: -1 } 1 is ASC, -1 is DESC
// - projection: [name,id,type]
//
await Magento2.get("/products", {
  filter: [{ field: "name", value: "hello", condition_type: "like" }, { field: "id", value: "5", condition_type: "eq" }],
  sort: { name: 1, sku: -1 },
  projection: [name,sku,price],
  currentPage: 2,
  pageSize: 20
});

// Basic POST example on coupons
//
await Magento2.post("/coupons", data);

// Basic PUT example on salesRules
//
await Magento2.put("/salesRules/SALESRULES_ID", data);

// Basic DELETE example on coupons
//
await Magento2.delete("/coupons/COUPON_ID");

Examples on usage with helpers (Note: Only Products, Coupons and SalesRules Helpers are included at this moment. More are coming)

// GET Coupon data by ID
//
await Magento2.coupons.getById("10");

// Get Coupon data by search criteria
//
await Magento2.coupons.get({
  filter: [{ field: "code", value: "%RE%", condition_type: "like" }],
  pageSize: 5,
  currentPage: 2
});

// Create a new Coupon
//
await Magento2.coupons.create(data);

// Update a coupon
//
await Magento2.coupons.update(couponID, data);

// Delete a coupon
//
await Magento2.coupons.delete(couponID);