Netsuite Python Tba Authentication
I am new to this area of using SOAP for NetSuite calls. Hence, I might be thinking completely incorrectly on how to solve the problem. Here is what I am trying to solve: - Language
Solution 1:
Hope the below code helps someone who is starting out.
base = '&'.join([nsAccountID, consumerKey, token, Nonce, currentTime])
key = '&'.join([consumerSecret, tokenSecret])
digest = hmac.new(str.encode(key), msg=str.encode(base), digestmod=hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()
tokenPassport = client.get_type('ns0:TokenPassport')
PassportSignature = client.get_type('ns0:TokenPassportSignature')
tokenPassportSignature = PassportSignature(signature, "HMAC-SHA256" )
clientPass = tokenPassport(account=nsAccountId, consumerKey = consumerKey, token= token, nonce= Nonce, timestamp=currentTime, signature=tokenPassportSignature)
search = client.get_type('ns5:ItemSearchBasic')
searchCriteriaComplex = client.get_type('ns0:SearchStringField')
searchCriteria = searchCriteriaComplex(searchValue= "Test Display Name - tax", operator="is")
searchItem = search(displayName = searchCriteria)
testRes = client.service.search(searchRecord= searchItem, _soapheaders={"tokenPassport": clientPass})
Solution 2:
Instead of did deeper on this, I tried netsuite which is much better.
Solution 3:
Here is how I generate the TokenPassport.
def_generateTimestamp(self):
returnstr(int(time()))
def_generateNonce(self, length=20):
"""Generate pseudorandom number
"""return''.join([str(random.randint(0, 9)) for i inrange(length)])
def_getSignatureMessage(self, nonce, timestamp):
return'&'.join(
(
self._setting['ACCOUNT'],
self._setting['CONSUMER_KEY'],
self._setting['TOKEN_ID'],
nonce,
timestamp,
)
)
def_getSignatureKey(self):
return'&'.join((self._setting['CONSUMER_SECRET'], self._setting['TOKEN_SECRET']))
def_getSignatureValue(self, nonce, timestamp):
key = self._getSignatureKey()
message = self._getSignatureMessage(nonce, timestamp)
hashed = hmac.new(
key=key.encode('utf-8'),
msg=message.encode('utf-8'),
digestmod=hashlib.sha256
).digest()
return base64.b64encode(hashed).decode()
@propertydeftokenPassport(self):
TokenPassport = self.getDataType("ns0:TokenPassport")
TokenPassportSignature = self.getDataType("ns0:TokenPassportSignature")
nonce = self._generateNonce()
timestamp = self._generateTimestamp()
tokenPassportSignature = TokenPassportSignature(
self._getSignatureValue(nonce, timestamp),
algorithm='HMAC-SHA256'
)
return TokenPassport(
account=self._setting['ACCOUNT'],
consumerKey=self._setting['CONSUMER_KEY'],
token=self._setting['TOKEN_ID'],
nonce=nonce,
timestamp=timestamp,
signature=tokenPassportSignature
)
Post a Comment for "Netsuite Python Tba Authentication"