Last active
January 25, 2023 15:30
-
-
Save W3BGUY/926db10609f6d625e7eb743f910415a4 to your computer and use it in GitHub Desktop.
Jitterbit Script to Call NetSuite REST API to Create Records
This file contains 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 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'; | |
$recordType='contact'; | |
$url='https://'+$ns_accountURL+'.suitetalk.api.netsuite.com/services/rest/record/v1/'+$recordType; | |
RunOperation("<TAG>Operations/00-Common/Common_Build_NS_Auth</TAG>",true); | |
</trans> |
This file contains 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=''; | |
$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> |
This file contains 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