Oracle Netsuite
Source
import datetime
import random
import string
import hashlib
import base64
import hmac
import urllib
oauth_consumer_id = '{{consumer_id}}' # Provide Values
oauth_consumer_key = '{{consumer_key}}' # Provide Values
oauth_consumer_secret ='{{consumer_secret}}' # Provide Values
oauth_token ='{{token}}' # Provide Values
oauth_token_secret ='{{token_secret}}' # Provide Values
###########################################################################################################################################################
request_method = 'POST'
url = 'https://{{hostname}}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql'
oauth_signature_method = 'HMAC-SHA256'
oauth_timestamp = str(int(datetime.datetime.now().timestamp()))
oauth_nonce = ''.join(random.choices(string.ascii_letters + string.digits, k = 11))
oauth_version = '1.0'
normalized_request_method = request_method.replace(' ', '')
normalized_string_url = urllib.parse.quote(url, safe = '')
normalized_params = {'oauth_consumer_key': oauth_consumer_key,'oauth_token': oauth_token,'oauth_signature_method': oauth_signature_method,'oauth_timestamp': oauth_timestamp,'oauth_nonce': oauth_nonce,'oauth_version': oauth_version,'limit':max_num,'offset':min_num}
sorted_params = dict(sorted(normalized_params.items()))
normalized_string_parmas = [k+'='+v for k,v in sorted_params.items()]
normalized_string_parmas = '&'.join([str(elem) for elem in normalized_string_parmas])
normalized_string_parmas.replace(' ','')
normalized_string_parmas = urllib.parse.quote(normalized_string_parmas, safe = '')
base_string = request_method + '&' + normalized_string_url + '&' + normalized_string_parmas
base_string = str.encode(base_string)
signature_key = oauth_consumer_secret + '&' + oauth_token_secret
signature_key = str.encode(signature_key)
oauth_signature = hmac.new(signature_key, base_string, hashlib.sha256)
oauth_signature.hexdigest()
oauth_signature = base64.b64encode(oauth_signature.digest())
oauth_signature = oauth_signature.decode('UTF-8')
oauth_signature = urllib.parse.quote(oauth_signature, safe = '')
signature ='OAuth realm="'f'{oauth_consumer_id}",oauth_consumer_key="'f'{oauth_consumer_key}",oauth_token="'f'{oauth_token}",oauth_signature_method="'f'{oauth_signature_method}",oauth_timestamp="'f'{oauth_timestamp}",oauth_nonce="'f'{oauth_nonce}",oauth_version="'f'{oauth_version}",oauth_signature="'f'{oauth_signature}"'
Target / Operations
import datetime
import random
import string
import hashlib
import base64
import hmac
import urllib.parse
oauth_consumer_id = '{{consumer_id}}' # Provide Values
oauth_consumer_key = '{{consumer_key}}' # Provide Values
oauth_consumer_secret ='{{consumer_secret}}' # Provide Values
oauth_token ='{{token}}' # Provide Values
oauth_token_secret ='{{token_secret}}' # Provide Values
###########################################################################################################################################################
request_method = 'POST'
url = 'https://{{account_id}}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql'
oauth_signature_method = 'HMAC-SHA256'
oauth_timestamp = str(int(datetime.datetime.now().timestamp()))
oauth_nonce = ''.join(random.choices(string.ascii_letters + string.digits, k = 11))
oauth_version = '1.0'
normalized_request_method = request_method.replace(' ', '')
normalized_string_url = urllib.parse.quote(url, safe = '')
normalized_params = {'oauth_consumer_key': oauth_consumer_key,'oauth_token': oauth_token,'oauth_signature_method': oauth_signature_method,'oauth_timestamp': oauth_timestamp,'oauth_nonce': oauth_nonce,'oauth_version': oauth_version}
sorted_params = dict(sorted(normalized_params.items()))
normalized_string_parmas = [k+'='+v for k,v in sorted_params.items()]
normalized_string_parmas = '&'.join([str(elem) for elem in normalized_string_parmas])
normalized_string_parmas.replace(' ','')
normalized_string_parmas = urllib.parse.quote(normalized_string_parmas, safe = '')
base_string = request_method + '&' + normalized_string_url + '&' + normalized_string_parmas
base_string = str.encode(base_string)
signature_key = oauth_consumer_secret + '&' + oauth_token_secret
signature_key = str.encode(signature_key)
oauth_signature = hmac.new(signature_key, base_string, hashlib.sha256)
oauth_signature.hexdigest()
oauth_signature = base64.b64encode(oauth_signature.digest())
oauth_signature = oauth_signature.decode('UTF-8')
oauth_signature = urllib.parse.quote(oauth_signature, safe = '')
signature ='OAuth realm="'f'{oauth_consumer_id}",oauth_consumer_key="'f'{oauth_consumer_key}",oauth_token="'f'{oauth_token}",oauth_signature_method="'f'{oauth_signature_method}",oauth_timestamp="'f'{oauth_timestamp}",oauth_nonce="'f'{oauth_nonce}",oauth_version="'f'{oauth_version}",oauth_signature="'f'{oauth_signature}"'
Note : In Oracle NetSuite Target/Operations pre-request script, users can select either the “POST” or “PATCH” method based on their requirements. Please specify the chosen method in the request_method parameter within the pre-request script.
Target / Operations for SOAP body
import os
import requests
import time
import hashlib
import hmac
import base64
import secrets
# Set your environment variables (replace with your actual credentials)
account = '{{account}}'
consumerKey = '{{consumerKey}}'
consumerSecret = '{{consumerSecret}}'
tokenId = '{{tokenId}}'
tokenSecret = '{{tokenSecret}}'
# Generate timestamp and nonce
timestamp = str(int(time.time()))
nonce = secrets.token_hex(11)
# Create base string
baseString = f"{account}&{consumerKey}&{tokenId}&{nonce}&{timestamp}"
# Create key
key = f"{consumerSecret}&{tokenSecret}"
# Create signature
signature = base64.b64encode(hmac.new(key.encode('utf-8'), baseString.encode('utf-8'), hashlib.sha256).digest()).deco
