Kevin Hoelzel
04/19/2024, 2:57 PMAnaFarms
04/19/2024, 4:36 PMKevin Hoelzel
04/19/2024, 4:37 PMverikott
04/19/2024, 4:46 PMKevin Hoelzel
04/19/2024, 4:47 PMKevin Hoelzel
04/19/2024, 4:48 PMbattk
04/22/2024, 1:01 PMbattk
04/22/2024, 1:02 PMbattk
04/22/2024, 1:08 PMKurt Dicus
04/26/2024, 9:56 PMMohit
05/06/2024, 1:50 PMMohit
05/06/2024, 2:50 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);
});
battk
05/06/2024, 4:20 PMbattk
05/06/2024, 4:25 PMMohit
05/06/2024, 7:38 PMChristian W.
06/22/2024, 8:22 PMKurt Dicus
06/22/2024, 8:49 PMChristian W.
06/22/2024, 11:51 PMChristian W.
06/22/2024, 11:55 PM