Code Monkey home page Code Monkey logo

js-api-sdk's Introduction

JavaScript SDK for MerchOne API integration

NPM Version License GitHub last commit

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:

Exception Reason
MerchOneApiClientError Request is not correct or validation did not pass.
MerchOneApiServerError A server error occurred.
InvalidApiVersionError An invalid API version was provided to the Client.
InvalidCredentialsError Invalid 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.

js-api-sdk's People

Contributors

allanvb avatar merch-one avatar

Watchers

 avatar

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.