I am newbie to Oracle Netsuite. I read and read their API document but can't find a proper solution.
I am using Token Based Authentication and enabled it on the account setting, and created an access token.
I have an administrator account logged in via browser and created an access token through the Netsuite UI.
Below is my node code.
const axios = require('axios');
const token = 'token';
// Define the URL and headers
const url = 'https://{accountID}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=2969&deploy=2&searchid=237';
const headers = {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
};
// Make the API request
axios.get(url, {
headers
})
.then(function (response) {
console.log(response.data.results);
})
.catch(function (error) {
console.log(error.response.data);
});
This gives an error : Invalid Login attempt.
I believe the token is correct and role is correct.
Please let me know what I am wrong.
Thank you!
I tried TBA token and account email/password. But it gives an error invalid login attempt. I also tried to enter the URL in browser and same error message shows.
I am expecting to get list of search results. Below is my Restlet script
/**
* @NApiVersion 2.x
* @NScriptType Restlet
*/
define(['N/search'], function (search) {
function getSearchResultsById(context) {
if (context.request.method !== 'GET') {
throw new Error('Invalid request method. Only GET requests are supported.');
}
var searchId =237
var script = search.load({
id: searchId
});
var searchResults = script.runPaged().data;
return {
results: searchResults
};
}
return {
get: getSearchResultsById
};
});