eminero
04/04/2024, 7:46 PMClay Roper
04/04/2024, 7:58 PMeminero
04/04/2024, 8:01 PMeminero
04/04/2024, 8:09 PMClay Roper
04/04/2024, 8:09 PMeminero
04/04/2024, 8:27 PMBerenice Domínguez
04/05/2024, 12:32 PMBerenice Domínguez
04/05/2024, 12:34 PMClay Roper
04/05/2024, 5:00 PMBerenice Domínguez
04/05/2024, 5:01 PMBerenice Domínguez
04/05/2024, 5:01 PMeminero
04/05/2024, 5:25 PMBerenice Domínguez
04/05/2024, 5:28 PMBerenice Domínguez
04/05/2024, 5:29 PMBerenice Domínguez
04/05/2024, 6:24 PMvar results = {};
const apiAuthorization = 'OAuth realm="123456_SB1",oauth_consumer_key="e9c90beb74d471e8b457b9b7931c4ddca3c96a57d4a88cb6cd23a4b85b5",oauth_token="6a59bd7d68ca9be7b6a542257dd42005ee02bc291b0559856633ae13",oauth_signature_method="HMAC-SHA256",oauth_timestamp="1710178192",oauth_nonce="NMN8TPc0fvu",oauth_version="1.0",oauth_signature="p9b/MNSBP2/uwGELRzyWQT5+kdHSs+UH7d/iWAoCOXs="';
fetch('<https://123456-SB1.suitetalk.api.netsuite.com/services/rest/record/v1/customer?limit=10>', {
headers: {
Authorization: apiAuthorization,
},
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(protectedData => {
console.log('Protected Data:', protectedData);
})
.catch(error => {
console.error('Error:', error);
});
Berenice Domínguez
04/05/2024, 6:24 PMBerenice Domínguez
04/05/2024, 6:25 PMvar axios = require('axios');
const apiAuthorization = 'OAuth realm="123456_SB1",oauth_consumer_key="e9c90beb74d471e8c6398b457b9bddca3c96a57d4a88cb6cd23a4b85b5",oauth_token="6a59bd7d68ca9be7b6a542257dd42005ee02bc291b0559856633ae13",oauth_signature_method="HMAC-SHA256",oauth_timestamp="1710178192",oauth_nonce="NMN8TPc0fvu",oauth_version="1.0",oauth_signature="p9b/MNSBP2/uwGELRzyWQT5+kdHSs+UH7d/iWAoCOXs="';
axios.get(
'<https://123456-SB1.suitetalk.api.netsuite.com/services/rest/record/v1/customer?limit=10>',
{
headers: {
Authorization: apiAuthorization,
}
}
).then(response => {
console.log(response.data);
}).catch(error => {
console.log(error);
});
Berenice Domínguez
04/05/2024, 6:28 PMdata: {
type: '<https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.2>',
title: 'Unauthorized',
status: 401,
'o:errorDetails': [Array]
}
Berenice Domínguez
04/05/2024, 6:29 PMeminero
04/05/2024, 6:32 PMBerenice Domínguez
04/05/2024, 6:36 PMBerenice Domínguez
04/05/2024, 6:54 PMBerenice Domínguez
04/05/2024, 6:56 PMBerenice Domínguez
04/08/2024, 2:44 PMBerenice Domínguez
04/08/2024, 2:45 PMvar NETSUITE_ACCOUNT_ID = '123456_SB1'
var BASE_URL = '<https://123456-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=1310&deploy=1>';
Berenice Domínguez
04/08/2024, 2:45 PMvar HTTP_METHOD = 'POST'
var SCRIPT_ID = '613'
var OAUTH_VERSION = '1.0';
var SCRIPT_DEPLOYMENT_ID = '1'
var TOKEN_ID = "123456"
var TOKEN_SECRET = "123456"
var CONSUMER_KEY = "123456"
var CONSUMER_SECRET = "123456"
var text = "";
var length = 32;
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
var OAUTH_NONCE = text;
var TIME_STAMP = Math.round(+new Date() / 1000);
var data = '';
//data = data + 'deploy=' + SCRIPT_DEPLOYMENT_ID + '&';
data = data + 'oauth_consumer_key=' + CONSUMER_KEY + '&';
data = data + 'oauth_nonce=' + OAUTH_NONCE + '&';
data = data + 'oauth_signature_method=' + 'HMAC-SHA256' + '&';
data = data + 'oauth_timestamp=' + TIME_STAMP + '&';
data = data + 'oauth_token=' + TOKEN_ID + '&';
data = data + 'oauth_version=' + OAUTH_VERSION + '&';
//data = data + 'script=' + SCRIPT_ID;
var encodedData = encodeURIComponent(data);
var completeData = HTTP_METHOD + '&' + encodeURIComponent(BASE_URL) + '&' + encodedData;
var hmacsha1Data = CryptoJS.HmacSHA256(completeData, CONSUMER_SECRET + '&' + TOKEN_SECRET);
// var base64EncodedData = Base64.stringify(hmacsha1Data);
var base64EncodedData = btoa(hmacsha1Data);
var oauth_signature = encodeURIComponent(base64EncodedData);
var OAuth = 'OAuth oauth_signature="' + oauth_signature + '",';
OAuth = OAuth + 'oauth_version="1.0",';
OAuth = OAuth + 'oauth_nonce="' + OAUTH_NONCE + '",';
OAuth = OAuth + 'oauth_signature_method="HMAC-SHA256",';
OAuth = OAuth + 'oauth_consumer_key="' + CONSUMER_KEY + '",';
OAuth = OAuth + 'oauth_token="' + TOKEN_ID + '",';
OAuth = OAuth + 'oauth_timestamp="' + TIME_STAMP + '",';
OAuth = OAuth + 'realm="' + NETSUITE_ACCOUNT_ID + '"';
// var request = <http://https.post|https.post>({
// url: BASE_URL + '?script=' + SCRIPT_ID + '&deploy=' + SCRIPT_DEPLOYMENT_ID,
// headers: { "Content-Type": "application/json", "Authorization": OAuth },
// body: JSON.stringify({ hello: "world" })
// })
const myHeaders = new Headers();
myHeaders.append('Authorization', OAuth);
myHeaders.append('Content-Type', 'application/json');
var myOptions = {
method: 'GET',
headers: myHeaders,
mode: 'no-cors',
cache: 'default',
// body: JSON.stringify({ hello: "world" })
};
var request = fetch(REST_API_BASE_URL, myOptions);
console.log('request', request);
var response = JSON.parse(request.body)
log.debug('response', response)
Berenice Domínguez
04/08/2024, 2:45 PMBerenice Domínguez
04/08/2024, 2:50 PMClay Roper
04/10/2024, 3:07 PMdeploy
and script
parameters included in the base string of your signatureBerenice Domínguez
04/10/2024, 3:09 PMClay Roper
04/10/2024, 3:11 PMBerenice Domínguez
04/10/2024, 3:21 PMBerenice Domínguez
04/10/2024, 3:40 PMBerenice Domínguez
04/10/2024, 3:41 PMerrno: -61,
code: 'ECONNREFUSED',
Mohit
05/06/2024, 1:46 PMMohit
05/06/2024, 2:51 PMconst crypto = require('crypto');
const axios = require('axios');
const credentials = require('./secret').credentials;
const ACCOUNT_ID = '12345_SB1';
const CONSUMER_KEY = credentials.CONSUMER_KEY;
const CONSUMER_SECRET = credentials.CONSUMER_SECRET;
const TOKEN = credentials.TOKEN;
const TOKEN_SECRET = credentials.TOKEN_SECRET;
const timestamp = Math.floor(Date.now() / 1000);
const nonce = (() => {
let nonce = ''
const alphaNum = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (let index = 20; index > 0; index--) {
nonce += alphaNum.charAt(Math.floor(Math.random() * alphaNum.length));
}
return nonce;
})();
console.log('timestamp:: ' + timestamp);
console.log('nonce:: ' + nonce);
const SIGNATURE_METHOD = 'HMAC-SHA256';
const urlParams = {
limit: 5,
};
const reqParams = {
...{
oauth_consumer_key: CONSUMER_KEY,
oauth_nonce: nonce,
oauth_signature_method: SIGNATURE_METHOD,
oauth_timestamp: timestamp,
oauth_token: TOKEN,
oauth_version: '1.0'
},
...urlParams
};
const encodeRFC3986URIComponent = (str) => {
return encodeURIComponent(str).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,);
}
const METHOD = 'GET';
const baseString = ((METHOD, url, reqParams) => {
let strReqParams = '';
const arrReqParamKeys = Object.keys(reqParams).sort();
for (let index = 0; index < arrReqParamKeys.length; index++) {
const name = arrReqParamKeys[index];
const value = reqParams[name];
if (index < arrReqParamKeys.length - 1) {
strReqParams += name + '=' + value + '&';
} else {
strReqParams += name + '=' + value;
}
}
return METHOD + '&' + encodeRFC3986URIComponent(url) + '&' + encodeRFC3986URIComponent(strReqParams);
})(METHOD, '<https://12345-sb1.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder>', reqParams);
const key = encodeRFC3986URIComponent(CONSUMER_SECRET) + '&' + encodeRFC3986URIComponent(TOKEN_SECRET);
console.log('\nbaseString:: ' + baseString);
const signature = crypto.createHmac('sha256', key)
.update(baseString)
.digest('base64');
console.log('\nsignature:: ' + signature);
axios.get('<https://12345-sb1.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder?limit=5>',
{
headers: {
Authorization: `OAuth realm="${ACCOUNT_ID}",oauth_consumer_key="${CONSUMER_KEY}",oauth_token="${TOKEN}",oauth_signature_method="${SIGNATURE_METHOD}",oauth_timestamp="${timestamp}",oauth_nonce="${nonce}",oauth_version="1.0",oauth_signature="${signature}"`,
Accept: '*/*',
"Cache-Control": "no-cache",
Connection: "keep-alive"
}
}
).then(response => {
console.log(response.data);
}).catch(error => {
console.log(error);
});
verikott
05/06/2024, 2:52 PM