Last active
January 25, 2023 15:33
-
-
Save W3BGUY/0dd442bd0acea32cda47bbc92c6fe7c5 to your computer and use it in GitHub Desktop.
Jitterbit Script to Call NetSuite REST API using SuiteQL Queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
01> Create transformation operation with script 01 as the first step. | |
02> Create script operation with step 02 as teh script (called by script 01 script). | |
03> Create JavaScript with contents from step 03 (called by Step 02 script). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Step 01 | |
<trans> | |
$httpMethod='POST'; | |
$paramKey1='limit'; | |
$paramVal1=20; | |
$paramKey2='offset'; | |
$paramVal2=20; | |
$url='https://'+$ns_accountURL+'.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql'; | |
RunOperation("<TAG>Operations/00-Common/Common_NetSuite_SuiteQL_Authentication</TAG>",true); | |
$restURL=$url+'?limit=20&offset=20'; | |
WriteToOperationLog('OAuth_Header: '+$OAuth_Header); | |
$SuiteQL_Query="SELECT * FROM Customer WHERE (Customer.IsInactive='F') ORDER BY Customer.EntityID"; | |
</trans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Step 02 | |
<trans> | |
$NS_REST_OAuth_Header=''; | |
$encodedSignature=''; | |
$signToBeEncoded=''; | |
$message=''; | |
$oauth_param_string=''; | |
$OAuth_Version='1.0'; | |
$signatureMethod='HMAC-SHA256'; | |
$jb.netsuite.account=trim($ns_accountID); | |
$jb.netsuite.tokenPassword.token=trim($ns_tokenKey); | |
$jb.netsuite.tokenPassword.consumerKey=trim($ns_consumerKey); | |
$jb.netsuite.tokenPassword.consumerSecret=trim($ns_consumerSecret); | |
$jb.netsuite.tokenPassword.tokenSecret=trim($ns_tokenSecret); | |
$jb.netsuite.tokenPassword.nounce=md5(Now_()); | |
$jb.netsuite.tokenPassword.timestamp=Int(Now()); | |
//Add additional lines for each host specific parameter if needed i.e.: | |
//{'parameter_name','parameter value'}, | |
oauth_params={ | |
{'oauth_token',$jb.netsuite.tokenPassword.token}, | |
{'oauth_consumer_key',$jb.netsuite.tokenPassword.consumerKey}, | |
{'oauth_nonce',$jb.netsuite.tokenPassword.nounce}, | |
{'oauth_timestamp',$jb.netsuite.tokenPassword.timestamp}, | |
{'oauth_version','1.0'}, | |
{'oauth_signature_method',$signatureMethod}, | |
{$paramKey1,$paramVal1}, | |
{$paramKey2,$paramVal2} | |
}; | |
//Sort all parameters in alphabetical order by key name | |
SortArray(oauth_params,0,false); | |
//Count the parameters | |
oauth_params_count=Length(oauth_params); | |
//Loop through the parameters to create the base parameter string | |
While(oauth_params_count>0, | |
$oauth_param_string=$oauth_param_string+oauth_params[oauth_params_count-1][0]+'='+oauth_params[oauth_params_count-1][1]+If(oauth_params_count>1,"&"); | |
oauth_params_count=oauth_params_count-1; | |
); | |
//Using HMAC-SHA256 Jitterbit Plugin to generate the signature | |
$Jitterbit.HMACSHA256.Signature=""; | |
$Jitterbit.HMACSHA256.Key=$jb.netsuite.tokenPassword.consumerSecret+'&'+$jb.netsuite.tokenPassword.tokenSecret; | |
$Jitterbit.HMACSHA256.Encoding="UTF-8"; // optional | |
//Encode Message (httpmethod+url+oauthparams) | |
RunScript("<TAG>Scripts/00-Common/Common_NS_Encode_oAuth_Params_and_Signature</TAG>"); | |
$Jitterbit.HMACSHA256.Message=$message; | |
RunPlugin("<TAG>plugin:http://www.jitterbit.com/plugins/pipeline/user/HMACSHA256Generator</TAG>"); | |
$signToBeEncoded=Base64Encode(HexToBinary($Jitterbit.HMACSHA256.Signature)); | |
//Encode the signature | |
RunScript("<TAG>Scripts/00-Common/Common_NS_Encode_oAuth_Params_and_Signature</TAG>"); | |
$NS_REST_OAuth_Header='Authorization: OAuth realm="'+$ns_accountID+'",oauth_consumer_key="'+$ns_consumerKey+'",oauth_token="'+$ns_tokenKey+'",oauth_signature_method="'+$signatureMethod+'",oauth_timestamp="'+$jb.netsuite.tokenPassword.timestamp+'",oauth_nonce="'+$jb.netsuite.tokenPassword.nounce+'",oauth_version="'+$OAuth_Version+'",oauth_signature="'+$encodedSignature+'"'; | |
$OAuth_Header='OAuth realm="'+$ns_accountID+'",oauth_consumer_key="'+$ns_consumerKey+'",oauth_token="'+$ns_tokenKey+'",oauth_signature_method="'+$signatureMethod+'",oauth_timestamp="'+$jb.netsuite.tokenPassword.timestamp+'",oauth_nonce="'+$jb.netsuite.tokenPassword.nounce+'",oauth_version="'+$OAuth_Version+'",oauth_signature="'+$encodedSignature+'"'; | |
</trans> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Step 03 | |
$message=$httpMethod+'&'+encodeURIComponent($url)+'&'+encodeURIComponent($oauth_param_string); | |
$encodedSignature=encodeURIComponent($signToBeEncoded); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added repo with a working Jitterpak: https://github.com/W3BGUY/Jitterbit_NetSuite_REST_API