Does anyone have documentation for using secrets i...
# suitescript
s
Does anyone have documentation for using secrets in NetSuite, kind of like an .env file
s
this is code i just made up but iwant to be to use it something like this
Copy code
var secretId = 'custsecret_your_secret_id';
      var secretValue = secret.get({ id: secretId });
becuase these are for external api i want to create them in the ui and then my scripts can make external api calls
the docs do not explain at all how to access form inside suite script
t
@Sim Greenbaum here is a sample using username and password saved as API secrets to call an external API https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_0111025229.html
s
const secStringKeyInBase64 = https.createSecureString({ input: "name_of script_id_created" });
you saying the api key i enter there ?
The Docs talk about using the key ,not how to pull them into my script
This is my test ID how would i get that info
Copy code
custsecretrails_seceret_id
b
The pieces are spread around my codebase rather widely, but I believe the patterns would look like this. Using the secret in a header (using createSecureString):
Copy code
var sKey = https.createSecureString({ input: "{custsecretrails_seceret_id}" });
//...
var header = new Array();
header["secret-header"] = sKey;
//...
var response = <http://https.post|https.post>({
  url: "https:\\<http://consoso.com|consoso.com>\api",
  body: JSON.stringify(obj),
  headers: header
});
Using the secret in the request body (using credentials field):
Copy code
var requestBody={
  secretFieldInRequest="{custsecretrails_seceret_id}",
  otherFieldInRequest="sample"
}
// ...
<http://https.post|https.post> ( {
    url      : url
    , headers: headers
    , credentials: ["custsecretrails_seceret_id"]
    , body   : body
} );
Either way, N/Https expands the secret on its way onto the wire. You never actually retrieve it (unless your request just happens to be aimed at a service like httpbin.org that will send your request back to you) .