Help libs to authenticate against the Sellmate REST API


Useful authentication module to help you connect your App with Sellmate. REST API Documentation is also available here.


$ npm install sellmate-utils

or add it to your project dependencies package.json

    "sellmate-utils": "*"

Quick start - OAuth2

  1. Create a new OAuth2 object with some parameters (host is optional, default is ''):

    var oa = new OAuth2(client_id, client_secret, redirectUri, host);
    e.g.: var oa = new OAuth2('1234', 'qwertasdfgzxcv', 'http://localhost:8888/callback');
  2. Get the OAuth Request Token URL and call it (parameters are optional, i.e. shop):

    var authUrl = oa.getAuthorizeUrl(params);
    e.g.: var authUrl = oa.getAuthorizeUrl({ 'shop': 'my-shop' });
  3. Your App should have a callback servlet (i.e. http://localhost:8888/callback) where you get the notification with the code as a query parameter. Then you can request an AccessToken:

    oa.getAccessToken(code, {
        'shop': 'my-shop',
        'grant_type': 'authorization_code',
    }, function(errorresponsebody) {
        // The body response contains some parameters among which you will  
        // find the `access_token` and the `refresh_token` 

Quick start - REST

  1. Create a new Rest object with the target url and the parameters needed for the authentication (mac_key and access_token):

    var target = "<shop-handle>/rest/<resource>";   
    var rest = new Rest(target, {
        "mac_key": "abcd",
        "access_token": "abcd"
  2. Use one of the four verbs CRUD to access a resource:

        // Handle callback 
  3. You can also request the Authorization Header with:

    var authHeader = rest.getAuthHeader();