domoinc / domo-node-sdk

NodeJS - Domo API SDK
https://developer.domo.com
MIT License
25 stars 11 forks source link

Constants mismatch in Transport.js #10

Open sstradling opened 7 years ago

sstradling commented 7 years ago

I'm getting the following error when attempting to call .datasets.list:

{ Error: Unable to GET /v1/datasets for Dataset at RequestException (/Users/sethstradling/Documents/Development/cerberus/node_modules/domo-sdk/dist/common/Errors.js:5:9) at request.catch (/Users/sethstradling/Documents/Development/cerberus/node_modules/domo-sdk/dist/common/Transport.js:20:24) at process._tickCallback (internal/process/next_tick.js:109:7) method: 'GET', type: 'Dataset', path: '/v1/datasets', error: TypeError: Constants_1.API_SCOPE[s].toLowerCase is not a function at scope.scopes.map.s (/Users/sethstradling/Documents/Development/cerberus/node_modules/domo-sdk/dist/common/Transport.js:76:46) at Array.map (native) at Transport.renewAccessToken (/Users/sethstradling/Documents/Development/cerberus/node_modules/domo-sdk/dist/common/Transport.js:72:14) at Transport.retryRequest (/Users/sethstradling/Documents/Development/cerberus/node_modules/domo-sdk/dist/common/Transport.js:105:25) at rp.catch.err (/Users/sethstradling/Documents/Development/cerberus/node_modules/domo-sdk/dist/common/Transport.js:101:32) at process._tickCallback (internal/process/next_tick.js:109:7) }

It appears that when Transport.js is processing/mapping scopes, the generated constants.API_SCOPE looks like: { '0': 'USER', '1': 'DATA', USER: 0, DATA: 1 } , and since I'm passing 'USER', the function is attempting to pass 0 to .toLowerCase().

Not sure why API_SCOPE is getting interpreted that way.

walexnelson commented 7 years ago

@sstradling

The client is expecting an array of enums which have been defined in the constants

The examples demonstrate how to use them

const { DomoClient } = require('../dist');
const { API_SCOPE } = require('../dist/common/Constants');

const clientId = process.env.DOMO_CLIENT_ID;
const clientSecret = process.env.DOMO_CLIENT_SECRET;
const host = 'api.domo.com';

// use the values defined in the enum
const scopes = [API_SCOPE.DATA];

const domo = new DomoClient(clientId, clientSecret, scopes, host);

We can support an array of strings too if that's preferred.