1.0.1 • Published 1 year ago

@merch-one/api v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

This package provide a set of tools that allow developers to easily integrate with MerchOne API.

Installation

npm install @merch-one/api

Overview


Introduction

Client provide 3 different API's to interact with.

  • Catalog API
  • Orders API
  • Shipping API

To get the list of available endpoints, please check MerchOne API Documentation


Basic Usage

  • Package exports 3 classes: Client, MerchOneApi, OrderStatus

Create an instance of Client

// import ES module
import { Client } from '@merch-one/api';

// require CommonJS module
const { Client } = require('@merch-one/api');

const client = Client.make();

function doSomething() {
    // authenticate client using credentials
    client.auth(
        'your-store-user',
        'your-store-key'
    )
    
    // or authenticate client using base64 encoded credentials
    client.basicAuth(
        btoa('your-store-user:your-store-key'),
    )
    
    /* Interact with Catalog API */
    const catalogApi = client.catalog();
    
    /* Interact with Orders API */
    const ordersApi = client.orders();
    
    /* Interact with Shipping API */
    const shippingApi = client.shipping();
    
    // switch API version you interact with
    client.setVersion(version);
    
    // get current API version
    client.getVersion();
}
  • The Client class accepts version parameter. Default value is set beta
    • See Helpers for available versions.

Helpers

// import ES module
import { MerchOneApi } from '@merch-one/api';

// require CommonJS module
const { MerchOneApi } = require('@merch-one/api');

// get the list of all available API versions
MerchOneApi.getVersions()
  • Class OrderStatus provides a full list of Order statuses.
// import ES module
import { OrderStatus } from '@merch-one/api';

// require CommonJS module
const { OrderStatus } = require('@merch-one/api');

// get the list of all available Order statuses
OrderStatus.all();

Check more in MerchOne API Documentation


Exceptions

The package can throw the following exceptions:

ExceptionReason
MerchOneApiClientErrorRequest is not correct or validation did not pass.
MerchOneApiServerErrorA server error occurred.
InvalidApiVersionErrorAn invalid API version was provided to the Client.
InvalidCredentialsErrorInvalid API credentials was provided to the Client.

Under the hood, the package uses Fetch API to make requests.

Make sure you checked Browser compatibility before using it.

Also take note that Fetch API is available in Node.js only since version 17.5 with flag --experimental-fetch. Starting from version 18.0, the flag is no longer required.