I was able to setup the Postman tutorials for the ...
# integrations
n
I was able to setup the Postman tutorials for the REST Web Services (thank @battk) . Now I am trying to use the REST services call through a web app. Here is what I have so far. I get invalid login error with the following code. A couple of specific questions I have. • The nonce generator only seems to produce numeric, which all the examples I see are alpha numeric. Not sure if that is a problem • I am not sure if this library
oauth-signature
can use
sha-256
. What library should I use to create the signature? Everything I see it looks like the token is generated through the service on the call. Should the library create the handle tokenization or should I be passing it in manually to create the signature?
Copy code
const oauthSignature = require('oauth-signature')
const NonceGenerator = require('a-nonce-generator')
const https = require('https')
 

 const nonce = new NonceGenerator().generate()
 
 const httpMethod = 'GET'
 const url = '<https://9999999-sb1.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder/3481015>'
 const parameters = {
    oauth_consumer_key: "7092e7fae232904dddccnn2348*88qencenb12452eda85d0302",
    oauth_token: "c676fc73fceb8fsdmfm32m42342371230b46dcb60cb",
    oauth_nonce: nonce.toString(),
    oauth_timestamp: Date.now().toString(),
    oauth_signature_method: 'HMAC-SHA256',
    oauth_version: '1.0'
 }
 const consumerSecret = "7546ffsdfs06c9716sd23324w8a976qw5604ea954a6wqewewef316faa0ee9f8b96awqe"
 const tokenSecret = "f70c22482591dsfsdffd4d17c9f86223cff86b97a3243236a2c9c82af1c1"

 // generates a BASE64 encode HMAC-SHA1 hash
 const signature = oauthSignature.generate(
 httpMethod,
 url,
 parameters,
 consumerSecret,
 tokenSecret,
 { encodeSignature: false }
 )
 
// console.log(encodedSignature)
// console.log(signature)
// console.log(oauth)

const oAuthString = `OAuth realm="9999999_SB1", oauth_consumer_key="7092e7fae232904dddccnn2348*88qencenb12452eda85d0302", oauth_token="c676fc73fceb8fsdmfm32m42342371230b46dcb60cb", oauth_signature_method="HMAC-SHA256",oauth_timestamp="${parameters.oauth_timestamp}", oauth_nonce="${parameters.oauth_nonce}", oauth_version="1.0", oauth_signature="${encodedSignature}"`

console.log(oAuthString)

https.get("<https://9999999-sb1.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder/3481015>", {
     headers: { 
         "Authorization": oAuthString.toString()
     }
 },(res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

  res.on('data', (d) => {
    process.stdout.write(d);
  });

}).on('error', (e) => {
  console.error(e);
});
n
Can you/ do you need to, use SHA256 with this package?
b
you can use whatever hmac the crypto module supports
the module requires using an external hash function
m
It might be a good idea to revoke these keys šŸ™ˆ
n
I sanitized everything lol
m
šŸ˜…
n
Thanks again @battk I was able to get it setup with
oauth-1.0a