Skip to content

Instantly share code, notes, and snippets.

@saqibarfeen
Last active July 24, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqibarfeen/bf69a42c85ecd21007b23ba49a1f95fd to your computer and use it in GitHub Desktop.
Save saqibarfeen/bf69a42c85ecd21007b23ba49a1f95fd to your computer and use it in GitHub Desktop.
/*
================= REQUIRED USER ACCOUNT INFORMATION ==============================================
To install pre-reqs:-
npm install request
npm install oauth-1.0a@1.0.1
*/
var accountID = '4541795_SB1';
var consumer = {
public: 'YOUR CLIENT ID',
secret: 'CLIENT SECRET'
};
var token = {
public: '<YOUR TOKEN ID>',
secret: '<YOUR TOKEN SECRET>'
};
//for example, https://YOURACCOUNTNUMBER.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=SCRIPTNUMBER&deploy=DEPLOYNUMBER
var restlet_url = 'https://4541795-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=237&deploy=1';
/*
=========================================================================================================
*/
//REQUIRED NPM MODULES
const request = require('request');
const OAuth = require('oauth-1.0a'); //version 1.0.1, don't do version 1.1.0
//SET UP THE OAUTH OBJECT
var oauth = OAuth({
consumer: consumer,
signature_method: 'HMAC-SHA256' //you can also use HMAC-SHA1 but HMAC-SHA256 is more secure (supposedly)
});
//SET UP THE REQUEST OBJECT
var request_data = {
url: restlet_url,
method: 'POST',
};
//GET THE AUTHORIZATION AND STICK IT IN THE HEADER, ALONG WITH THE REALM AND CONTENT-TYPE
var authorization = oauth.authorize(request_data, token);
var header = oauth.toHeader(authorization);
header.Authorization += ', realm="' + accountID + '"';
header['content-type'] = 'application/json';
//MAKE THE REQUEST
request({
url: request_data.url,
method: request_data.method,
headers: header,
json: {"action":"createinvoice",
"data": [
{
"invoiceId" : "3888-invoice",
"saleOrderId" : "9876",
"origin" : "3890",
"invoiceDate" : "10/26/2019 10:09:08 PM",
"name": "INV/0001",
"stripeTransactionId": "abc13",
"item" : [
{
"invoiceLineId" : "76861",
"quantity": "1",
"saleOrderLineId" : "6723",
"productServiceAmount" : "26.44"
}
]
}
]
}
}, function(error, response, body) {
if(error)
{
console.log(error);
}
else
{
console.log(body);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment