How can send external API data into a RESTlet?

I’m trying to send external API data into NetSuite using OAuth 1.0. Specifically, I’m trying to create a POST request in my code which will send over the email of the user into a RESTlet.  It is returning the error “Failed to load resource: the server responded with a status of 401 (Unauthorized)” and “error code: INVALID_LOGIN_ATTEMPT error message: Invalid login attempt.“. However, I’m able to complete the POST request in Postman and the audit trail says it was successful: Role: NetSuite Connector Web Services Status: Success. Here is my code. How can I create this fetch request to be included in an external source which will send over information to NetSuite?

<script>
var myHeaders = {}
var consumerKey = "c522a20d4a5617fa5524c42cfed2****"
var consumerSecret = "670c560678fac3cbe16e523d7a****"
var oAuthToken = "96b90daa97097fa6076a83b59eb958a****"
var oAuthTokenSecret = "789e6eefb1fae6a565fb011bff1****"
var oAuthMethod = "HMAC-SHA256"
var oAuthVersion = "1.0"
var realm = "*******"
var oAuth_signature="vu9eYP117WPjweElnzYmIWHXI8AcWPJK6%2FYFNoqcfd0%3A"
var timeStamp = Math.round(+new Date()/1000)
var nonce = "kfz7VFp0EP6"
 
var auth = `OAuth realm=${realm},oauth_consumer_key="${consumerKey},oauth_token="${consumerSecret}",oauth_signature_method="${oAuthMethod}",oauth_signature="${oAuth_signature}",oauth_timestamp="${timeStamp}",oauth_nonce="${nonce}",oauth_version="${oAuthVersion}"`
myHeaders["Content-Type"] = "application/json"
myHeaders["Authorization"] = auth
 
var raw = JSON.stringify({
"recordType":"customer",
"companyname":"Emily",
"email":"e.jarecki@shopmedvet.com",
"category": "9",
"subsidiary": "1"
});
 
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow',
crossorigin: true,
mode: 'no-cors',
};
 
fetch("https://*******.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=2266&deploy=1", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.error('error', error));
</script>
Rookie Asked on January 8, 2024 in SuiteTalk.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   SuiteMigration   Become a Sponsor