# magento-api-rest-legacy

> A NodeJS wrapper to work with Magento V1 REST APIs.

Latest version **0.0.4** (published 2021-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install magento-api-rest-legacy
pnpm add magento-api-rest-legacy
yarn add magento-api-rest-legacy
bun add magento-api-rest-legacy
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-02-03 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Aaditya Chakravarty |
| Maintainers | aadityachakravarty |
| Keywords | Magento, eCommerce, REST, API, JS, NodeJS, Javascript, JSON |

## Links

- npm: https://www.npmjs.com/package/magento-api-rest-legacy
- Repository: https://github.com/aaditya/magento-api-rest-legacy
- Homepage: https://github.com/aaditya/magento-api-rest-legacy#readme
- Issues: https://github.com/aaditya/magento-api-rest-legacy/issues
- npm.io page: https://npm.io/package/magento-api-rest-legacy

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [oauth-1.0a](https://npm.io/package/oauth-1.0a.md) ^2.2.6

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.4 (latest) — 2021-02-03
- 0.0.3 — 2021-02-03

## README

# Magento API REST (Legacy)

A Node.js client wrapper to work with the Magento 1.X REST API.

[![npm version](https://badge.fury.io/js/magento-api-rest-legacy.svg)](https://www.npmjs.com/package/magento-api-rest-legacy)
[![dependencies Status](https://david-dm.org/aaditya/magento-api-rest-legacy/status.svg)](https://david-dm.org/aaditya/magento-api-rest-legacy)

## Installation

```
npm i magento-api-rest-legacy
```

## Getting started

Generate API credentials by following [these instructions](https://devdocs.magento.com/guides/m1x/api/rest/introduction.html).

Make sure to check the resource access is as per your requirements to prevent misuse of the API Keys.

* This library is compatible only with Magento 1.X REST Endpoints for Magento 2.X based stores, use the [sister package](https://www.npmjs.com/package/magento-api-rest).

## Setup

Setup for the Magento REST API integration:

```js
const MagentoAPI = require('magento-api-rest-legacy');

const client = new MagentoAPI({
    'url': 'http://www.your-store.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                               |
| `timeout`           | `Number`  | no       | Request Timeout                                            |
| `axiosConfig`       | `Object`  | no       | [Reference](https://github.com/axios/axios#request-config) |

## 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.                             |

* Note: In case no params are specified or required, you can leave params as empty. 
That will result in "?searchCriteria=all" in the URL. 

### 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](https://github.com/axios/axios) with [support to promises](https://github.com/axios/axios#promises).

```js
let params = {
    "filter": [
        {
            "attribute": "entity_id",
            "neq": 3,
            "in": [1,2,3],
            "nin": [1,2,3],
            "gt": 3,
            "lt": 3,
            "from": "Date",
            "to": "Date"
        }
    ],
    "page": 1,
    "order": "name",
    "dir": "dsc", // Or asc
    "limit": 100
}
```

If you want to use the above object in a request,
```js
async function getOrders () {
    try {
        let response = await client.get('orders', params);
        // Response Handling
    } catch (error) {
        // Error Handling
    }
}
```

---
_Source: https://npm.io/package/magento-api-rest-legacy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
