Skip to content

Instantly share code, notes, and snippets.

@W3BGUY
Last active January 25, 2023 16:08
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 W3BGUY/95e1ec92ff8dacc15dcbd210e95670c5 to your computer and use it in GitHub Desktop.
Save W3BGUY/95e1ec92ff8dacc15dcbd210e95670c5 to your computer and use it in GitHub Desktop.
Jitterbit Script to Call the GET NetSuite REST API - use with (NS_Encode_oAuth_Params_and_Signature.js)
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).
//Step 01
<trans>
$httpMethod='GET';
$recordType='contact';
$recordID=123; // NS Internal ID
$url='https://'+$ns_accountURL+'.suitetalk.api.netsuite.com/services/rest/record/v1/'+$recordType+'/'+$recordID;
RunOperation("<TAG>Operations/00-Common/Common_Build_NS_Auth</TAG>",true);
</trans>
//Step 02
<trans>
$NS_REST_OAuth_Header='';
$encodedSignature='';
$signToBeEncoded='';
$message='';
$oauth_param_string='';
$nsNonce=Left(md5(Now_()),11);
$nsTimestamp=Int(Now()); // Gets Unix timestamp
oauth_params={
{'oauth_token',$ns_tokenKey},
{'oauth_consumer_key',$ns_consumerKey},
{'oauth_nonce',$nsNonce},
{'oauth_timestamp',$nsTimestamp},
{'oauth_version',$ns_oAuthVersion},
{'oauth_signature_method',$ns_signatureMethod}
};
SortArray(oauth_params,0,false);
oauth_params_count=Length(oauth_params);
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;
);
RunScript("<TAG>Scripts/00-Common/Common_NS_Encode_oAuth_Params_and_Signature</TAG>");
$Jitterbit.HMACSHA256.Signature="";
$Jitterbit.HMACSHA256.Key=$ns_consumerSecret+'&'+$ns_tokenSecret;
$Jitterbit.HMACSHA256.Message=$message;
RunPlugin("<TAG>plugin:http://www.jitterbit.com/plugins/pipeline/user/HMACSHA256Generator</TAG>");
$signToBeEncoded=Base64Encode(HexToBinary($Jitterbit.HMACSHA256.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="'+$ns_signatureMethod+'",oauth_timestamp="'+$nsTimestamp+'",oauth_nonce="'+$nsNonce+'",oauth_version="'+$ns_oAuthVersion+'",oauth_signature="'+$encodedSignature+'"';
WriteToOperationLog("OAuth header: "+$NS_REST_OAuth_Header);
WriteToOperationLog("OAuth_Header: "+$OAuth_Header);
</trans>
//Step 03
$message=$httpMethod+'&'+encodeURIComponent($url)+'&'+encodeURIComponent($oauth_param_string);
$encodedSignature=encodeURIComponent($signToBeEncoded);
@W3BGUY
Copy link
Author

W3BGUY commented May 25, 2022

Added repo with a working Jitterpak: https://github.com/W3BGUY/Jitterbit_NetSuite_REST_API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment