I've been trying to feed a secret created from the...
# suitescript
j
I've been trying to feed a secret created from the UI 'API Secrets' page through to a https post though not having any luck.
var secureToken = https.createSecureString({             input: 'custsecret_mypassword'         });         var response = https.request({             url: 'https://ptsv2.com/t/999999/post',             method: 'POST',             credentials:[secureToken],             body: 'My POST Data:  ' + secureToken         });
doco says that the secure token can be used in the https.request credentials parameter which will replace the reference in the body with the decrypted password. The examples are a bit skinny and I've become stuck. Any ideas?
b
your body is a string, adding your secure string to a string just creates a normal string that wont have any credentials in it
use the secure string as the body
👍 1
if you include the credentials as a parameter to your request, you can also just use the secret's script id in your body as a normal string
use {custsecret_mypassword} as the string you would want replaced
j
thanks battk - I've changed the secure string as the body, though it seems that it's not grabbing the password from the field from the API Secrets - It's returning the script id. var secureToken = https.createSecureString({ input: 'custsecret_mypassword' }); var response = https.request({ url: 'https://ptsv2.com/t/vsrfd-999999/post', method: 'POST', credentials:[secureToken], body: secureToken }); comes through as:
b
all the credential stuff in request works by string replacement
where expressions are denoted as beginning with { and ending with }
use {custsecret_mypassword} as the string you would want replaced
custsecret_mypassword by itself is treated as a normal string
j
i think the request is replacing sucessfully - the secureToken param is being replaced with custsecret_mypassword
though https.createSecureString is not pulling my password from the API Secret?
b
okay, then do the boring thing of making your secure string input "im a normal string"
your post body will be the perfectly normal string
because it has no template expression in it
j
got it...
thanks Battk - the string input for the secureToken needs the scriptID to be wrapped
b
i personally find it easier to not use the secure string at all
you put the id of the secret in the credentials parameters
and the request will automatically do the string replacement without using a secure string
j
Thanks for the tip - i tried though could not get the body to do the string replacement. It replaced the parameter though. var response = https.request({ url: 'https://ptsv2.com/t/999999/post?credentials='+'{custsecret_mypassword}', method: 'POST', body: 'test body ' + '{custsecret_mypassword}' });
b
need to set the options.credentials parameter