Skip to content

Instantly share code, notes, and snippets.

View thuutien's full-sized avatar

Huu Tran thuutien

View GitHub Profile
@thuutien
thuutien / export.js
Created October 17, 2023 18:39
SuiteScript for exporting search to file cabinet
/**
*@NApiVersion 2.x
*@NScriptType ScheduledScript
*/
define(['N/task','N/log'],
function(task)
{
function execute(context)
{
@thuutien
thuutien / TokenPassport.cs
Last active September 21, 2023 16:53
Netsuite Token Passport Generation
public TokenPassport CreateTokenPassport()
{
String nonce = ComputeNonce();
long timestamp = ComputeTimestamp();
string account = ConfigurationManager.AppSettings["login.acct"];
string consumerKey = ConfigurationManager.AppSettings["login.tbaConsumerKey"];
string consumerSecret = ConfigurationManager.AppSettings["login.tbaConsumerSecret"];
string tokenId = ConfigurationManager.AppSettings["login.tbaTokenId"];
string tokenSecret = ConfigurationManager.AppSettings["login.tbaTokenSecret"];
TokenPassportSignature signature = ComputeSignature(account, consumerKey, consumerSecret, tokenId, tokenSecret, nonce, timestamp);
@thuutien
thuutien / SOAPRequest.cs
Created September 21, 2023 16:49
Successful NetSuite Saved Search SOAP .NET core
NetSuiteService nss = new NetSuiteService();
nss.Url = "https://your-accountID.suitetalk.api.netsuite.com/services/NetSuitePort_2023_1";
nss.tokenPassport = CreateTokenPassport(); //
TransactionSearchAdvanced tranSearch = new TransactionSearchAdvanced(); //TransactionSearchAdvanced type depends on your search object references.
tranSearch.savedSearchId = "searchID here";
try
{
var searchResult = nss.search(tranSearch);
if (searchResult.status.isSuccess)
@thuutien
thuutien / Authenticate.cs
Created September 19, 2023 20:32
Authenticate NetSuite functions
private string ComputeNonce()
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] data = new byte[20];
rng.GetBytes(data);
int value = Math.Abs(BitConverter.ToInt32(data, 0));
return value.ToString();
}
private long ComputeTimestamp()
@thuutien
thuutien / GetSavedSearch.xml
Last active September 19, 2023 20:31
Get Saved Search NetSuite SOAP
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:messages="urn:messages_2023_1.platform.webservices.netsuite.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<urn:tokenPassport xmlns:urn="urn:messages_2023_1.platform.webservices.netsuite.com">
<ns8:account xmlns:ns8="urn:core_2023_1.platform.webservices.netsuite.com">********</ns8:account>
<ns8:consumerKey xmlns:ns8="urn:core_2023_1.platform.webservices.netsuite.com">************</ns8:consumerKey>
<ns8:token xmlns:ns8="urn:core_2023_1.platform.webservices.netsuite.com">*************</ns8:token>
@thuutien
thuutien / SOAPRequest.xml
Last active September 19, 2023 14:42
NetSuite SOAP Token Base Request Example
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:messages_2023_1.platform.webservices.netsuite.com" xmlns:urn1="urn:core_2023_1.platform.webservices.netsuite.com">
<soapenv:Header>
<urn:tokenPassport>
<urn1:account>ACC_ID</urn1:account>
<urn1:consumerKey>CON_KEY</urn1:consumerKey>
<urn1:token>TO_ID</urn1:token>
<urn1:nonce>NONCE</urn1:nonce>
<urn1:timestamp>TIMESTAMP</urn1:timestamp>
<urn1:signature algorithm="HMAC_SHA256">COMPUTED_KEY</urn1:signature>
</urn:tokenPassport>
@thuutien
thuutien / GetData.cs
Last active September 19, 2023 14:42
RestSharp API Call for NetSuite
public static async Task getData()
{
var oAuth1 = OAuth1Authenticator.ForAccessToken(
consumerKey: CONSUMER_KEY,
consumerSecret: CONSUMBER_SECRET,
token: TOKEN_ID,
tokenSecret: TOKEN_SECRET,
OAuthSignatureMethod.HmacSha256
);