I'm struggling to understand how to use a credential field in a suitelet. The help documentation in NetSuite seems very poor / incomplete in this area. I've successfully used form.addCredentialField before in conjunction with the SFTP module, so I do have some experience with this.
But now, I'm trying to use a credential field to store an authorization token for a service I'm trying to connect to. It uses basic authentication. If I simply copy/past the auth token directly in the script, it works fine:
...
var actualToken = "abc123";
var authorization = encode.convert({ string: accountSID + ':' + actualToken, outputEncoding: encode.Encoding.BASE_64 });
const response = https.post({ url: sampleURL, headers: { Authorization: 'Basic ' + authorization }, body: 'test' });
...
The above works fine. But with a GUID, I can't figure it out. NS Help shows something about using https.createSecureString, but then it uses the result as if it is a string, which it isn't. The closest I've come is doing this:
var tokenGUID = (get this);
var authorization = encode.convert({ string: accountSID + ':' + tokenGUID, outputEncoding: encode.Encoding.BASE_64 });
const response = https.post({ url: sampleURL, headers: { Authorization: 'Basic ' + authorization }, body: 'test', credentials: [tokenGUID] });
But that doesn't work. Does anybody know how to do this?
Thank you