Giter Club home page Giter Club logo

node-bigcommerce's Introduction

Bigcommerce for Node.js

Build Status

A node module for authentication and use with the BigCommerce API

Installation

To install the module using NPM:

npm install node-bigcommerce

Or Yarn:

yarn add node-bigcommerce

Setup

Include the 'node-bigcommerce' module within your script and instantiate it with a config:

const BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  logLevel: 'info',
  clientId: '128ecf542a35ac5270a87dc740918404',
  secret: 'acbd18db4cc2f85cedef654fccc4a4d8',
  callback: 'https://myapplication.com/auth',
  responseType: 'json',
  headers: { 'Accept-Encoding': '*' }, // Override headers (Overriding the default encoding of GZipped is useful in development)
  apiVersion: 'v3' // Default is v2
});
Instantiating a BigCommerce instance without a config object will result in an error

Authorization

Set up your Big Commerce as above and pass the following configuration options in:

{
  clientId: 'Your application's client ID',
  secret: 'Your secret',
  callback: 'The location you want the app to return to on success',
  responseType: 'json'
}

You will be able to get your Client ID and Secret within your application setup. Below is an example using Express' routes:

const express = require('express'),
  router = express.Router(),
  BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  clientId: '128ecf542a35ac5270a87dc740918404',
  secret: 'acbd18db4cc2f85cedef654fccc4a4d8',
  callback: 'https://myapplication.com/auth',
  responseType: 'json'
});

router.get('/auth', (req, res, next) => {
  bigCommerce.authorize(req.query)
    .then(data => res.render('integrations/auth', { title: 'Authorized!', data: data })
    .catch(next);
  });
});

The authorize method requires the query parameters from the request to be passed. These are required to request a permanent access token which will be passed back in the data object.

An example data object:

{
  access_token: '9df3b01c60df20d13843841ff0d4482c',
  scope: 'store_v2_orders_read_only store_v2_products_read_only users_basic_information store_v2_default',
  user: {
    id: 12345,
    username: 'John Smith',
    email: '[email protected]'
  },
  context: 'stores/x43tqo'
}

From this object you can store the access_token for re-use when calling the Big Commerce API.

Load & Uninstall

The only configuration element required to use the verify method (used for both load and uninstall endpoints) is secret. Below is an example using Express' routes:

const express = require('express'),
  router = express.Router(),
  BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  secret: 'acbd18db4cc2f85cedef654fccc4a4d8',
  responseType: 'json'
});

router.get('/load', (req, res, next) => {
  try {
    const data = bigCommerce.verify(req.query['signed_payload']);
    res.render('integrations/welcome', { title: 'Welcome!', data: data });
  } catch (err) {
    next(err);
  }
});

The verify method requires the signed_payload query parameter to be passed from the request. This is used to verify that the request has come from Big Commerce. The verify method returns the following object:

{
  user: {
    id: 12345,
    email: '[email protected]'
  },
  context: 'stores/x43tqo',
  store_hash: 'x43tqo',
  timestamp: 1421748597.4395974
}

This will allow you to automatically log the user in (if required) when BigCommerce calls the load endpoint or remove/label a user that has uninstalled your application from their Big Commerce account.

Calling the API

The API can be called once the user has been authorized and has an access token. There is a helper for each type of request available within Big Commerce (GET, POST, PUT, DELETE).

To make an API Request you will need the following minimum configuration:

{
  clientId: 'Your application's client ID',
  accessToken: 'Token assigned to the user during authorisation',
  storeHash: 'The short hash for the store',
  responseType: 'json'
}

Parameters that are added to the url need to be escaped before they are passed as part of the path of any call:

const path = '/products?name=' + escape('Plain T-Shirt');

GET

The Get call requires a path: get(path):

const BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  clientId: '128ecf542a35ac5270a87dc740918404'
  accessToken: '9df3b01c60df20d13843841ff0d4482c',
  responseType: 'json'
});

bigCommerce.get('/products')
  .then(data => {
    // Catch any errors, or handle the data returned
  });

POST & PUT

The 'POST' & 'PUT' calls requires a path with optional data to be sent: post(path, data):

var BigCommerce = require('node-bigcommerce');

var bigCommerce = new BigCommerce({
  clientId: '128ecf542a35ac5270a87dc740918404'
  accessToken: '9df3b01c60df20d13843841ff0d4482c',
  responseType: 'json'
});

var product = {
  name: 'Plain T-Shirt',
  type: 'physical',
  description: 'This timeless fashion staple will never go out of style!',
  price: '29.99',
  categories: [18],
  availability: 'available',
  weight: '0.5'
}

// Replace 'post' with 'put' for a put call
bigCommerce.post('/products', product)
  .then(data => {
  // Catch any errors, or handle the data returned
  });

DELETE

The 'DELETE' call requires a path: delete(path). A delete call will not return any data and will return a response status of 204.

const BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  clientId: '128ecf542a35ac5270a87dc740918404',
  accessToken: '9df3b01c60df20d13843841ff0d4482c'
});

bigCommerce.delete('/products/' + productId)
  .then(() => {
  // Catch any errors, data will be null
  });

Debugging

We use debug, so just run with environment variable DEBUG set to node-bigcommerce:*

$ DEBUG=node-bigcommerce:* node my_test.js

Response Type

You may require the Big Commerce API to return data in a specific format. To return in either JSON or XML just add a 'responseType' to the config:

const BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  logLevel: 'info',
  clientId: '128ecf542a35ac5270a87dc740918404',
  accessToken: '9df3b01c60df20d13843841ff0d4482c',
  responseType: 'xml'
});

bigCommerce.post('/products?name=' + escape('Plain T-Shirt'))
  .then(data => {
  // Catch any errors, data will be null
  });

Note that when returning in JSON the data will be parsed into an object, XML will not, and will return a string. When no response type is given the type will resort to whatever the BigCommerce default is.

Webhooks can only be JSON so when dealing with the '/hooks' endpoint leave the responseType blank (or null).

Testing

yarn test

Contributing

This module was originally written to be used with Conversio and is used in a production environment currently. This will ensure that this module is well maintained, bug free and as up to date as possible.

Conversio's developers will continue to make updates as often as required to have a consistently bug free platform, but we are happy to review any feature requests or issues and are accepting constructive pull requests.

node-bigcommerce's People

Contributors

chriseff avatar dependabot[bot] avatar dlebech avatar jmnsf avatar kirtithorat avatar paveltiunov avatar philspitler avatar rfink avatar rickcraig avatar stefanosala avatar syjsdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-bigcommerce's Issues

Mistake in documentation for verify method?

The documentation shows verify method as a Promise, i.e. bigCommerce.verify(...).then()

However, the verify method seems to synchronously return the data object itself, rather than a Promise. Is this a mistake in the documentation?

Cant get token bigCommerce.authorize

I dont have a problem to report. I just need help.

The following is what my app looks like now.

const BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
    logLevel: 'info',
    clientId: 'from app creation',
    secret: 'from app creation',
    callback: 'http://localhost:3200/auth',
    responseType: 'json',
    apiVersion: 'v3',
    accessToken: 'from an api account created in bc store admin',
    storeHash: 'ziq4j28bpo'
});


router.get("/auth", (req, res, next) => {
    bigCommerce
        .authorize(req.query)
        .then(data => res.render("auth", { title: "Authorized!", data: data }))
        .catch(next);
});

What can I do now to get the token? I am trying GET http://localhost:3200/api/auth but that returns a message "you are being redirected to"... It must be obvious to most but I cant figure out how to use the authorize function. Please Help!

Instructions for oAuth

Thank you in advance! I am struggling here.

Can you please provide complete instructions on how my users can authenticate and receive their token. There are scattered instructions between your readme and the BigCommerce docs but the exact process with nodejs is very cryptic. Any help on this is appreciated.

Using promises

Hello!

Are you going to add promise support in foreseeable future?

I would also suggest adding support to usage of work 'authorize' to 'authorise'. I'm used to using 'authorize', though both variants are possible :)

4xx/5xx response body gets swallowed

If the API responds with a 4xx or 5xx code, it's next to impossible to get the response body, because it's swallowed here:

const error = new Error(`Request returned error code: ${res.statusCode} and body: ${body}`);

The only way would be to parse it from the Error's message, which would be very ugly.

Allow gzip,deflate encoding

Allow gzip/deflate encoding, as the BigCommerce API allows this (at least in V3), and some larger requests get limited to 8mb responses if they aren't encoded. Pull request incoming

Basic Auth

Is there a way to just do Basic Auth with this, or is this OAuth only? I am new to this so forgive my ignorance, but I am trying to test this using a get request:

`var BigCommerce = require('node-bigcommerce');

var bigCommerce = new BigCommerce({
clientId: '128ecf542a35ac5270a87dc740918404'
accessToken: '9df3b01c60df20d13843841ff0d4482c',
responseType: 'json'
});

bigCommerce.get('/products', function(err, data, response){
// Catch any errors, or handle the data returned
// The response object is passed back for convenience
});`

However I am getting an error saying I need the store hash

Unable to Auth, Load, Uninstall

I haven't had a lot of experience in using node and BigCommerce together and this is really my first time trying. I've been stuck on a problem for several days now and was wondering if I could get some support here. I have a NodeJS deployed on Amazon's AWS EB, at the moment when I try to install my draft App on BigCommerce, it gets stuck in the installation and the progress indicator stays indefinitely.

At the moment my config looks like:

const bigCommerce = new BigCommerce({
    logLevel: "info",
    clientId: "my id",
    secret: "my secret",
    callback: "hostname",
    responseType: "json",
    apiVersion: "v3" // Default is v2
});

and the code I'm using for auth, load, uninstall:

const app = express();
const router = express.Router();

router.get("/auth", (req, res, next) => {
    bigCommerce
        .authorize(req.query)
        .then(data => res.render("auth", { title: "Authorized!", data: data }))
        .catch(next);
});

router.get("/load", (req, res, next) => {
    try {
        const data = bigCommerce.verify(req.query["signed_payload"]);
        res.render("load", { title: "Welcome!", data: data });
    } catch (err) {
        next(err);
    }
});

router.get("/uninstall", (req, res, next) => {
    try {
        const data = bigCommerce.verify(req.query["signed_payload"]);
        res.render("uninstall", { title: "Uninstalled!", data: data });
    } catch (err) {
        next(err);
    }
});

app.use(router);

I've also tried using regular app.get('/', cb) as well, nothing.
Also I've seen the following get returned in data by auth:

{ title: "Authorized!", data: "<html><body>You are being <a href="https://login.bigcommerce.com/login">redirected</a>.</body></html>" }

I'm not quite sure how to approach this, and there isn't too much documentation on working with node and BC together =( If I could get some advice or perhaps pointed to the direction of where I might be able to get some it'd be greatly appreciated!

Thanks!

Adding support to 'authorize' naming

As mentioned here: #11 it could be cool to add 'authorize' function names as a lot of libraries are doing that and some developers are used to this sort of naming :)

Allow use of an https agent

Allow use of an https agent, keep-alive would reduce socket usage in a high volume environment. Pull request incoming.

401 Unauthorized - "X-Auth-Client and X-Auth-Token headers are required"

Hi,

Following the docs, we have put together the following snippet which fails with a 401 and the error message of "X-Auth-Client and X-Auth-Token headers are required":

import BigCommerce from 'node-bigcommerce'
...

const bigCommerce = new BigCommerce({
  clientId: 'xyz',
  accessToken: 'abc',
  storeHash: 'some_shop',
  responseType: 'json',
  apiVersion: 'v3'
})

bigCommerce.get('/catalog/products')
  .then(data => {
    console.log('data')
  })

However, using Postman with the same properties does return the data that is expected.

We are testing the JavaScript in a localhost application using Chrome dev tools.

Any ideas as to what may be causing the issue? I believe it may be a CORS issue but I am not certain.

Simple question around auth..

Hi, looking for some advice..

So I have created an app for BigCommerce. In the BigCommerce app I have the auth callback configured so that it calls my backend

`
export async function oauth(event, context, callback) {

bigCommerce.authorize(JSON.stringify(event.queryStringParameters))
    .then(data => {

        console.log('Authorized! ' + JSON.stringify(data));


        callback(null, {
            statusCode: 302,
            headers: {
                Location: '<some path in my app>',
            },
        })


    }).catch(error => {
        callback(null, failure(error));

    });

}

`

when I authorize I get something like the following back fro bigcommerce {"context":"stores/xxxx","code":"gpkof3rxxxxxxxwqjkv77dffq7w","scope":"store_v2_default"}

So I assume I do something like this:

  • I save this store and code somewhere in the backend - i.e. in session .. or db in my case as I am using a stateless auth pattern with a react single page app.
  • I send the code 'gpkof3rxxxxxxxwqjkv77dffq7w' back to the frontend (probably encrypted) where it is stored safely in a the browser session or cookie.
  • The code is sent in all subsequent requests (in the header) and used to identify the user making the requests

have I got this correct ? thanks

Does this module help get the customers token

In my app my customers will need to login as if they were on the bc store. I am able to verify that the provided email and password are correct. I cant find a method to exchange the user_id and my app credentials for a token that can be used in sso (described here)

I used the python sdk before and the part I want to do now in nodejs is the following

bc_client = b.api.BigcommerceApi(client_id, store_hash, access_token)
login_token = sdk.customer_login_token.create(bc_client, customer.id)

Error Response returns Gzip

Hi,
All my errors come in gzipped, is there a way to handle this without an external package?
My config is using apiVersion:3.

Error: cb is not a function

In generic request errors (such as timeout), the library fails if used with promises, as the callback function is not supplied:

Error: Error: socket hang up
/Users/rfink/code/node-bigcommerce/lib/request.js:156
return cb(e);
^

TypeError: cb is not a function
at ClientRequest. (/Users/rfink/code/node-bigcommerce/lib/request.js:156:12)
at emitOne (events.js:115:13)
at ClientRequest.emit (events.js:210:7)
at TLSSocket.socketCloseListener (_http_client.js:377:9)
at emitOne (events.js:120:20)
at TLSSocket.emit (events.js:210:7)
at _handle.close (net.js:549:12)
at TCP.done [as _onclose] (_tls_wrap.js:350:7)

Pull request incoming

SSO integration

Hi, BigCommerce provides different types of authentication nowadays. While going through the library I couldn't see an SSO integration basically which generates a single sign-in URL. Source

While going through the official library I saw there are methods to achieve it. It's a small piece of code easy to plugin. But at the same time I didn't see any implementation of SSO in this library. Have I missed it or the implementation is missing?

Sample code from Official Library

/**
     * @param int $id
     * @param string $redirectUrl
     * @param string $requestIp
     * @return string
     */
    public static function getCustomerLoginToken($id, $redirectUrl = '', $requestIp = '')
    {
        if (empty(self::$client_secret)) {
            throw new Exception('Cannot sign customer login tokens without a client secret');
        }

        $payload = array(
            'iss' => self::$client_id,
            'iat' => time(),
            'jti' => bin2hex(random_bytes(32)),
            'operation' => 'customer_login',
            'store_hash' => self::$store_hash,
            'customer_id' => $id
        );

        if (!empty($redirectUrl)) {
            $payload['redirect_to'] = $redirectUrl;
        }

        if (!empty($requestIp)) {
            $payload['request_ip'] = $requestIp;
        }

        return JWT::encode($payload, self::$client_secret, 'HS256');
    }

SPA front end app question

I am implementing a a Big Commerce (BC) app which will be a single page app created from React.js. There will be no backend/node.js server but rather multiple serverless api gateway endpoints that will be called from the react.js app.

correct me if I am wrong on the way things should work in terms of authentiation with my app:

  1. User logs into BC, installs and then launches my app
  2. my app will receive an oauth token from BC and store it in session storage
  3. for each request that my app makes to my serverless functions it should pass along the oauth token and on the server side the node-bigcommerce module should be used to verify this oauth token.
    4 A valid token allows login to my app otherwise acccess is denied

Do we have verifyJWT method for BigCommerce class?

For the tutorial for creating the BigCommerce App, there is a function call verifyJWT. However, I cannot find that from the class here

https://developer.bigcommerce.com/docs/ZG9jOjE4MjIyODMy-step-2-connect-your-app-to-big-commerce

I tried to replace verify with verifyJWT on the tutorial that doesn't work. Is that such a function that we can use?

A copy of the code from the tutorial: https://github.com/bigcommerce/sample-app-nodejs/blob/step-3-add-database/lib/auth.ts
Screenshot

main_full (8)

Can't write metadata?

Hi everyone, could you please advise on how to PUT to update a product's metadata?

Specifically I'm trying to update ShipperHQ metadata. I can get the existing metadata fields this way:

await bigCommerce.get(
       "/products/24751",
     );

And that gives me:

Got existing metadata =  { data:
   [ { id: 18352,
       key: 'shipping-groups',
       value: '["foo"]',
       namespace: 'shipping.shipperhq',
       permission_set: 'write',
       resource_type: 'product',
       resource_id: 24751,
       description: 'ShipperHQ shipping group rules associated with this product/sku',
       date_created: '2018-11-07T16:03:40+00:00',
       date_modified: '2018-11-07T16:03:40+00:00' },
     { id: 18353,
       key: 'shipping-origins',
       value: '["baz"]',
       namespace: 'shipping.shipperhq',
       permission_set: 'write',
       resource_type: 'product',
       resource_id: 24751,
       description: 'ShipperHQ shipping origins associated with this product/sku',
       date_created: '2018-11-07T16:03:40+00:00',
       date_modified: '2018-11-07T16:03:40+00:00' } ],

But when I try to write metadata using a PUT, BigCommerce complains:

 product.metadata = [{
        namespace: "shipping.shipperhq",
        key: "shipping-groups",
        value: '["update1"]',
      }]

const productUpdateRes = await bigCommerce.put(
      "/products/24769",
      product
    );

"The supplied namespace shipping.shipperhq is invalid."

I have tried every possible variation of "shipping", "global", "shipping-groups", etc for the namespace. Nothing seems to work.

Any ideas?

feature to add access token saved in Mongo

Hello,

This isn't an issue but a feature request.

It would be great if node-bigcommerce could have an option to save the access object to a mongodb db. This is the only thing I am missing and I am struggling to get this working with my app.

Great module :)

Many thanks

Trying to get product metafields give 404

I am trying to use the /catalog/products/{product_id}/metafields endpoint to fetch metafields for the product. This product whose id I used exists, it has a metafields and the store api credentials are valid. But I keep getting this response.
Metafield Request Response

Why is this so and how to get around this problem?
I have also tried /products/{product_id}/metafields as the get request endpoint.

The code I am trying.

const bigCommerce = new BigCommerce({
  storeHash: 'xxxxxxxx',
  clientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  accessToken: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  responseType: 'json',
});

module.exports = {
  fetchProductMetafields: productId => {
    
    return bigCommerce.get(`/catalog/products/${productId}/metafields`)
    .then(metafields => {
      return metafields;
    });
  }
}

Am I doing something wrong?

Everything but 200 resulting in stacktrace error

So I've been getting a nasty error anytime I hit something other than a 200. I've seen this similar stacktrace when I hit a 401 and 404 as well as 500.

{ Error: Request returned error code: 500 and body: 
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Error</title>
        <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAlFJREFUeNqUU8tOFEEUPVVdNV3dPe8xYRBnjGhmBgKjKzCIiQvBoIaNbly5Z+PSv3Aj7DSiP2B0rwkLGVdGgxITSCRIJGSMEQWZR3eVt5sEFBgTb/dN1yvnnHtPNTPG4PqdHgCMXnPRSZrpSuH8vUJu4DE4rYHDGAZDX62BZttHqTiIayM3gGiXQsgYLEvATaqxU+dy1U13YXapXptpNHY8iwn8KyIAzm1KBdtRZWErpI5lEWTXp5Z/vHpZ3/wyKKwYGGOdAYwR0EZwoezTYApBEIObyELl/aE1/83cp40Pt5mxqCKrE4Ck+mVWKKcI5tA8BLEhRBKJLjez6a7MLq7XZtp+yyOawwCBtkiBVZDKzRk4NN7NQBMYPHiZDFhXY+p9ff7F961vVcnl4R5I2ykJ5XFN7Ab7Gc61VoipNBKF+PDyztu5lfrSLT/wIwCxq0CAGtXHZTzqR2jtwQiXONma6hHpj9sLT7YaPxfTXuZdBGA02Wi7FS48YiTfj+i2NhqtdhP5RC8mh2/Op7y0v6eAcWVLFT8D7kWX5S9mepp+C450MV6aWL1cGnvkxbwHtLW2B9AOkLeUd9KEDuh9fl/7CEj7YH5g+3r/lWfF9In7tPz6T4IIwBJOr1SJyIGQMZQbsh5P9uBq5VJtqHh2mo49pdw5WFoEwKWqWHacaWOjQXWGcifKo6vj5RGS6zykI587XeUIQDqJSmAp+lE4qt19W5P9o8+Lma5DcjsC8JiT607lMVkdqQ0Vyh3lHhmh52tfNy78ajXv0rgYzv8nfwswANuk+7sD/Q0aAAAAAElFTkSuQmCC">
        <style>
            html, body, pre {
                margin: 0;
                padding: 0;
                font-family: Monaco, 'Lucida Console', monospace;
                background: #ECECEC;
            }
            h1 {
                margin: 0;
                background: #A31012;
                padding: 20px 45px;
                color: #fff;
                text-shadow: 1px 1px 1px rgba(0,0,0,.3);
                border-bottom: 1px solid #690000;
                font-size: 28px;
            }
            p#detail {
                margin: 0;
                padding: 15px 45px;
                background: #F5A0A0;
                border-top: 4px solid #D36D6D;
                color: #730000;
                text-shadow: 1px 1px 1px rgba(255,255,255,.3);
                font-size: 14px;
                border-bottom: 1px solid #BA7A7A;
            }
        </style>
    </head>
    <body>
        <h1>Oops, an error occurred</h1>
        <p id="detail">
            This exception has been logged with id <strong>75kime1lk</strong>.
        </p>
    </body>
</html>
    at IncomingMessage.<anonymous> ([scrubbed for privacy reasons]/node-bigcommerce/lib/request.js:103:21)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:128:9) code: 500 }
 { Error: Request returned error code: 404 and body: [{"status":404,"message":"The requested resource was not found."}]
     at IncomingMessage.<anonymous> ([scrubbed for privacy reasons]/node-bigcommerce/lib/request.js:103:21)
     at emitNone (events.js:91:20)
     at IncomingMessage.emit (events.js:185:7)
     at endReadableNT (_stream_readable.js:974:12)
     at _combinedTickCallback (internal/process/next_tick.js:80:11)
     at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:128:9) code: 404 }

Any idea what I can do to make sure this doesn't happen? I'm using the git version to the best of my knowledge as my package json reads
"node-bigcommerce": "git://github.com/getconversio/node-bigcommerce.git",

V3 Themes API Not Working

Hi, I am trying to get my stores current theme but this does not seem to be working:

themes api

var BigCommerce = require('node-bigcommerce');

var bigCommerce = new BigCommerce({
  clientId: 'clientId',
  storeHash: 'hash',
  accessToken: 'token',
  responseType: 'json'
});

bigCommerce.get('/themes', function(err, data, response){
  console.log(data)
});

I am getting this error

(node:64686) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Request returned error code: 404 and body: The route is not found, check the URL

Tested PR #80

I tested PR #80 and this fixes the gibberish when receiving errors.
Is it possible to merge this?

bigCommerce.delete doesn't work

After adding a product to my cart like this:

function addToCart(req){
	return new Promise(
		(resolve, reject) => {
		bigCommerce.post('/carts', {
			"line_items": [
				{
					"quantity": req.body.amount,
					"product_id": req.body.id,
					"variant_id": req.body.variant_id
				}
			]
		})
			.then(data => {
				resolve(data)
			})
			.catch(err => reject(err))
	});
}
app.post('/:route/:productName/add-to-cart', (req, res) => {
	const contentType = req.get('Content-Type')
	addToCart(req)
		.then( data => {
			req.session.cartId = data['data'].id
			if(contentType === 'text/plain') {
				res.render('checkout', data)
			}
			if(contentType === 'application/json') {
				res.json(data)
			}
		})
		.catch(err => console.error(err))
})

I try to remove the product like this:

function deleteFromCart(req){
	return new Promise(
		(resolve, reject) => {
			bigCommerce.delete(`/carts/${req.session.cartId}/items/${req.body.id}`)
				.then(data => {
					resolve(data)
				})
				.catch(err => reject(err))
	});
}
app.post('/update-cart', (req, res) => {
	const contentType = req.get('Content-Type')
	deleteFromCart(req)
		.then( data => {
			if(contentType === 'text/plain') {
				res.render('checkout', data)
			}
			if(contentType === 'application/json') {
				res.json(data)
			}
		})
		.catch(err => console.error(err))
})

When trying this with the same product, data will return the same quantity of 1 which was added in the addToCart function. I've tried swapping it with put and setting the quantity to 0 without success.
Am I missing something?

Post /hooks giving 404, resource not found.

I have the following block of code to allow me to install the webhooks onto a client store.

var config = require('../config');
var BigCommerce = require('node-bigcommerce');
var _ = require("lodash");
var async = require("async");

var install_webhooks = function(req,data,next){
	req.bigCom = new BigCommerce({
		"logLevel":"info",
		"clientId": config.bigcom_config.clientId,
		"accessToken":data.bigcom_token,
		"storeHash": data.bigcom_hash.split("/")[1],
		"responseType":"json"
	});

	var webhook_settings = {
		"scope":"store/order/created",
		"destination":config.bigcom_config.callback+"/new_orders",
		"is_active":true,
	};

	async.waterfall([
		function(next){
			console.log(JSON.stringify(webhook_settings,null,2));
			req.bigCom.post('/hooks',webhook_settings,function(err,data,response){
				next(err,data,response);
			})
		},
		function(data,response,next){
			console.log(data);
			console.log(response);
			next();
		}
	],function(err){
		next(err);
	});
}

My results are as follows...

Installing Webhooks
{
"scope": "store/order/created",
"destination": "https://09c18e00.ngrok.io/new_orders",
"is_active": true
}
Info: Requesting Data from: https://api.bigcommerce.com/stores/vbo4xq/v2/hooks.json Using the post method
Info: Starting Request, with options: { hostname: 'api.bigcommerce.com',
path: '/stores/{hash}/v2/hooks.json',
method: 'POST',
port: 443,
headers:
{ 'User-Agent': 'node-bigcommerce/2.1.0',
'Content-Type': 'application/json',
'X-Auth-Client': 'correct clientId',
'X-Auth-Token': 'correct auth token',
'Content-Length': 101 } }
Info: Sending Data: {"scope":"store/order/created","destination":"https://09c18e00.ngrok.io/new_orders","is_active":true}
Info: Status Returned: 404
Info: Headers Returned: {"server":"nginx","date":"Tue, 17 Jan 2017 20:37:17 GMT","content-type":"application/json; charset=utf-8","content-length":"66","connection":"keep-alive","x-bc-stapler":"1","cache-control":"no-cache","x-bc-store-version":"7.6.0","x-newrelic-app-data":"PxQDVV5bARABUFJaAQcEREgTYVYAMhEDXhFZAUxRW1xvSmwTWD0cCwpSUhlIE1BDEkhRTAcBB1ZUHQYdUlVbUwROFVMUGlEBV11YUAhVUFFSVQ8EB1saH1YFDRFSbA==","x-bc-apilimit-remaining":"20000"}
Info: Request complete
Error: Request failed with code: 404 and body: [{"status":404,"message":"The requested resource was not found."}]
{ [Error: Request failed with code: 404 and body: [{"status":404,"message":"The requested resource was not found."}]] code: 404 }

I've also found that removing the .json extension causes it to work, but commenting it out completely makes the system return XML which is not what I'm looking to use at this time (unless I have no other choice)

Any help to make it better would be nice. Thank you for your time.

missing proxy agent on auth request

missing adding the agent to the request options for the auth request

async authorize(query) {
    if (!query) throw new Error('The URL query paramaters are required.');

    const payload = {
      client_id: this.config.clientId,
      client_secret: this.config.secret,
      redirect_uri: this.config.callback,
      grant_type: 'authorization_code',
      code: query.code,
      scope: query.scope,
      context: query.context
    };

    const request = new Request('login.bigcommerce.com', {
      failOnLimitReached: this.config.failOnLimitReached
    });

    return await request.run('post', '/oauth2/token', payload);
  }

should be

async authorize(query) {
    if (!query) throw new Error('The URL query paramaters are required.');

    const payload = {
      client_id: this.config.clientId,
      client_secret: this.config.secret,
      redirect_uri: this.config.callback,
      grant_type: 'authorization_code',
      code: query.code,
      scope: query.scope,
      context: query.context
    };

    const request = new Request('login.bigcommerce.com', {
      failOnLimitReached: this.config.failOnLimitReached,
      agent: this.config.agent
    });

    return await request.run('post', '/oauth2/token', payload);
  }

Handle request errors

Adding .on('error') handler for https requests, as socket hang ups can crash an app. Pull request incoming.

Error response are gibberish \u001f‹\b\u0000\u0000\u0000\u0000\u0000\u0000\u00004Ž»\u000eÂ0\fEÅ\nk\u001fRÅԙ…\u001f\b‰i-µq°ÝJ¨ê¿“\n\u0018,ÝáÜ{¼95o‹ºþÜu•3²\t]ïn¤Ji\u0000\u0016 \u0014X\

Do you no why my error responses from BigCommerce are not readable?

"error": "Error: Request returned error code: 422 and body: \u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u00004�»\u000eÂ0\fEÅ\nk\u001fRÅÔ����\u001f\b�i-µq°ÝJ¨ê¿�\n\u0018,ÝáÜ{¼95o�ºþÜu�3²\t]ïn¤Ji\u0000\u0016 \u0014X\u0004��àk!Á\bOÂ)ª+ø;\u001fôh�µoÛ�+N�Q�\u0007\r�ç\u0019%`SBë3�ÊÕ_Y\u001d8âÑG\u0011�âÞÜê�|²2v\u001fI!\u000bÇ¥(G¯ÀÙ��Vðcàz��ü¿qûþ\u0001\u0000\u0000ÿÿ\u0003\u0000ÿ\u001byÇÅ\u0000\u0000\u0000"

Use v3 for catalog API

Catalog API is now at V3, which is backwards compatible, but enables new features. Addressed by #18.

invalid response as "you are being redirected to login page"

Hi,
I would like to know why I am getting the response as
<html><body>You are being <a href="https://login.bigcommerce.com/login">redirected</a>.</body></html> when I should have got an example data object as mentioned in the documentation.
Here is my code snippet.

var app = express();
BigCommerce = require('node-bigcommerce');

const bigCommerce = new BigCommerce({
  logLevel: 'info',
  clientId: '(Removed for obvious reasons)',
  secret: '(Removed for obvious reasons)',
  callback: 'https://priyanamdtest.mybigcommerce.com',
  responseType: 'json',
  apiVersion: 'v3' 
});

app.get('/auth', function(req, res, next) {
  bigCommerce
    .authorize(req.query)
    .then(data => res.write(data))
    .catch(next);
});

var port = process.env.PORT || 8080;
app.listen(port);

module.exports = app;

Install node-bigcommerce error

I installed node-bigcommerce.
But node-bigcommerce is not working when i run stencil start .
image
Is there any way to fix this?
Thanks

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.