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

magento-api-rest-next

v2.1.2

Published

A NodeJS wrapper to work with Magento REST APIs.

Downloads

65

Readme

Magento API REST

A Node.js client wrapper to work with the Magento REST API.

Installation

npm i magento-api-rest-next

Getting started

Generate API credentials by following these instructions.

Make sure to check the resource access is as per your requirements to prevent misuse of the API Keys.

Check out the Magento API endpoints and data that can be manipulated in these docs.

Setup

Setup for the Magento REST API integration

ECMAScript Module Example

import Magento from "magento-api-rest-next";

const client = new Magento({
    'url': 'https://magento.dev',
    'consumerKey': '<OAuth 1.0a consumer key>',
    'consumerSecret': '<OAuth 1.0a consumer secret>',
    'accessToken': '<OAuth 1.0a access token>',
    'tokenSecret': '<OAuth 1.0a access token secret>',
});

CommonJS Module Example

const Magento = require('magento-api-rest-next').default;

const client = new Magento({
    'url': 'https://magento.dev',
    'consumerKey': '<OAuth 1.0a consumer key>',
    'consumerSecret': '<OAuth 1.0a consumer secret>',
    'accessToken': '<OAuth 1.0a access token>',
    'tokenSecret': '<OAuth 1.0a access token secret>',
});

Options

| Option | Type | Required | Description | --- | --- | --- | --- | url | String | yes | Your Store URL | | consumerKey | String | yes | Your API consumer key | | consumerSecret | String | yes | Your API consumer secret | | accessToken | String | yes | Your API Access Token | | tokenSecret | String | yes | Your API Access Token Secret | | type | String | no | Magento endpoint type, default is 'V1'| | sha | Number | no | Magento SHA type, default is '1'| | timeout | Number | no | Request Timeout | | axiosConfig | Object | no | Reference

If you want to use the Asynchronous Endpoints set type to async/V1.

If you want to use the Bulk Endpoints set type to async/bulk/V1.

If you want to change the sha version, values can be 1 or 256.

Methods

GET

.get(endpoint) .get(endpoint, params)

| Params | Type | Description | |------------|----------|---------------------------------------------------------------| | endpoint | String | Magento API endpoint, example: orders | | params | Object | JSON object to be sent as params. |

POST

.post(endpoint, data)

| Params | Type | Description | |------------|----------|-------------------------------------------------------------| | endpoint | String | Magento API endpoint, example: shipments | | data | Object | JSON object to be sent as body. |

PUT

.put(endpoint, data)

| Params | Type | Description | |------------|----------|-------------------------------------------------------------| | endpoint | String | Magento API endpoint, example: shipments/12 | | data | Object | JSON object to be sent as body. |

DELETE

.delete(endpoint, data)

| Params | Type | Description | |------------|----------|-----------------------------------------------------------------| | endpoint | String | Magento API endpoint, example: orders/12 | | data | Object | JSON object to be sent as body. |

API

Requests are made with Axios library with support to promises.

let params = {
     "filter_groups": [
        {
            "filters": [
                {
                    "field": "created_at",
                    "value": "2019-08-03 11:22:47",
                    "condition_type": "from"
                }
            ]
        },
        {
            "filters": [
                {
                    "field": "created_at",
                    "value": "2020-08-03 11:22:47",
                    "condition_type": "to"
                }
            ]
        }
    ],
    "sort_orders": [
        {
            "field": "created_at",
            "direction": "desc"
        }
    ],
    "page_size": 200,
    "current_page": 1
}

Or, you can use the parser to write the above query as:

let params = {
    $from: "2019-08-03 11:22:47",
    $to: "2020-08-03 11:22:47",
    $sort: {
        "created_at": "desc"
    },
    $perPage: 200,
    $page: 1
}

You cannot use both the param writing styles together. Parser is triggered automatically if you use any of the keys.

Parser Operators

| Operator | Description | Notes ---|---|--- | $or | Execute OR queries. | Syntax: $or:[ { condition1 }, { condition2 }] | | $from | Starting point of search via ISO date. | Requires $to. | | $to | Ending point of search via ISO date. | Requires $from. | | $after | Search after a specific ISO date. | Exclusive. | | $before | Search before a specific ISO date. | Exclusive. | | $sort | Sort the data. | | $perPage | Specifies the per page data. | | $page | Specifies the current page. |

By default { key: value } translates to an "eq" operation where key = value.

To get more information as to how to form search queries, use the following reference.

If you want to use the above object in a request,

async function getOrders () {
    try {
        let { data } = await client.get('orders', params);
        // Response Handling
    } catch (err) {
        // Error Handling
    }
}

Error Handling is same as how Axios handles it.