Hello - Question on `API Secrets` I need to execut...
# suitescript
m
Hello - Question on
API Secrets
I need to execute an
https
call, where a static token is being passed in the
https body
So, for example:
Copy code
const bodyObj = {
    "user": "my_user",
    "token": ...........
}
I stored the token securely, using
API Secrets
Looking at the documentation, it seems that I can only use it now as a direct parameter, but not in a body like this one. Any thoughts?
e
I spent a bit trying to figure out if this is possible. Here’s the problem I see. If the API you’re calling requires a Content-Type header of application/json, then NetSuite requires the body be a string, not an object. And if you pass in a string to the body parameter, I don’t believe you can pass in a secure string.
b
there are 2 ways to accomplish this, both requiring you to understand how template engines work
the first is the body as a plain string, in which case you need to specify the credentials parameter and then have the api secret's id in an template expression in the body somewhere so that it will be eventually replaced
👍 1
the alternative is a SecureString, which will basically be the same solution, but does not require you to specify a credentials parameter and to instead place the template expression in the input of the SecureString. You then use the SecureString as the body of the request
e
Cool. Had not heard of that first option.
m
@battk - I couldn't find how to do this with templates, so I'm calling a
suitelet
via
https
and grabbing the value from there If you have an example with
templates
, it'd be great to look at it : ) Thanks!
b
you will need to be more specific, every example in N/https Module Script Samples uses template expressions
some better than others