The question is rather vague, but I indeed will be very grateful for any advice/help: e.g. use a different tool (not the npm module I mentioned below), or how to debug authorization errors etc.
What I've been trying to do is to set up an environment to allow a CLI access to NetSuite, so that I could manipulate records w/o using a web browser.
My choice landed on the netsuite-rest npm module.
I enabled features in my test account:
- SOAP WEB SERVICES (probably not relevant for the REST API, but I'm mentioning it, since it's enabled)
- REST WEB SERVICES
- TOKEN-BASED AUTHENTICATION
- DISABLE HMAC-SHA1 FOR TOKEN-BASED AUTHENTICATION (I had not seen this feature mentioned in any help section, but I decided to enable it, since the netsuite-rest npm module seems to use the HMAC-SHA256 algorithm, so I disabled HMAC-SHA1 but it hasn't helped)
- OAUTH 2.0 (probably not relevant in my case, since I use TBA in the integration record settings, but I'm mentioning it, since it's enabled)
Also I created a role and assigned it to my user. The role has these permissions:
- Setup sub tab:
- Log in using Access Tokens
- REST Web Services
- User Access Tokens
- Lists sub tab:
Also I created an integration record, where I checked the TOKEN-BASED AUTHENTICATION checkbox and unchecked the OAuth 2.0 checkboxes.
And I created an access token (where I was prompted with my user), so I'm pretty sure it was created correctly.
But when I try to perform an API request:
'use strict';
const nsApiWrapper = require('netsuite-rest');
const nsApi = new nsApiWrapper({
consumer_key: 'aaa',
consumer_secret_key: 'bbb',
token: 'ccc',
token_secret: 'ddd',
realm: 'tstdrv1234',
});
nsApi
.request({
path: 'record/v1/customer/',
method: 'GET',
})
.then(response => console.log('No error', response))
.catch((err) => console.log('!error!', err));
I always receive the 401 Unauthorized error.
Could anyone help me with this, please?
---------------------
Also I noticed that the XLSX file with permission (which is available in the official NetSuite help section) mentioned the Web Services permission. But in my role there is no such permission available for selection. Just FYI, not sure if it's a bug in the help or I haven't enabled a necessary feature.
-----------------------
Thank you.