Has anyone found a workaround to POST an HTTPS req...
# suitescript
b
Has anyone found a workaround to POST an HTTPS request with a JSON body that includes a SecureString? In order to get the body to go as JSON, it appears I have to JSON.stringify it first. But that drops any secure strings included in the object. Passing the object itself to https.post or https.request causes it to switch to x-www-form-urlencoded and drop the contents of any sub-objects (i.e.
auth
in the example below). In no case does the https module ever seem to send my Content-Type="application/json" header.
Copy code
//const authSecret = https.createSecureString({input:"{custsecret_msi_secret_key}"});
  const authSecret = "super secret";
  const requestBody={
    someField: "someValue",
    auth: {
      company:"xyz", 
      secretKey:authSecret
      }
  };
  
  const requestOptions = {
    method: <http://https.Method.POST|https.Method.POST>,
    url: "<https://httpbin.org/anything>",
    headers: [{name:"Content-Type", value:"application/json"}],
//    body: JSON.stringify(requestBody)
    body: requestBody
  };
  const response = https.request(requestOptions );
b
two approaches you can try
the first is to use the credentials parameter, which allows you to use guids/secrets in the string of the post body
it allows you to not use the secure string at all
the second approach is to use the input of the secure string, it allows you to put a lot more than just the secret in there
both approaches rely on understanding that the guid/secret is used as a data source for a template that N/https renders
b
Thank you, @battk, awesome as always!
Example code, if anyone else stumbles into this before it ages out of the Slack channel:
Copy code
const requestBody={
        someField:123,
        auth: {
            company:"pdq",
            secret: "{custsecret_msi_secret_key}"
        }
    };
    const jsonBody=JSON.stringify(requestBody);
    const requestHeaders=[];
    requestHeaders['Content-Type']="application/json";
    const requestOptions = {
        url: "<https://httpbin.org/anything>",
        headers: requestHeaders,
        credentials:["custsecret_msi_secret_key"],
        body: jsonBody
    };
    const response = <http://https.post|https.post>(requestOptions );