guys I'm stuck. i'm trying to set up Basic authent...
# suitescript
m
guys I'm stuck. i'm trying to set up Basic authentication for an https request, using a password from a credential field GUID. I create a secure string with the username:guid to use in the headers, but i keep getting unexpected errors. has anybody done this before?
b
There is a lot to get wrong
What does the code to create your credential field look like
In general ill be looking to make sure you chose the domain and script restrictions correctly
If that looks okay, ill want to see how your http request looks like
m
yep the credential field side seems to be doing its job, i think the issues i'm having are around using SecureStrings. The documentation is woeful. have you used those before? i could show you this on a screenshare if that might help
b
you are doomed if you try to use the secure string
your header needs to look like
Basic QWxhZGRpbjpPcGVuU2VzYW1l
thats a mix of base 64 and utf-8
secure strings only allow one encoding
my advice to you is to base64 your username:password and use that instead
Copy code
var guid = "f33875aa66404e5b998c6cdfa6c22b21";
<http://https.post|https.post>({
  url: "<https://httpbin.org/post>",
  credentials: [guid],
  headers: {
    Authorization: "Basic {" + guid + "}"
  }
});
m
oooh, that makes sense. and I see that you do use the credentials attribute in the https.post
did you find all this through experience? or is that documented somewhere?
b
terribly documented
m
ok i'm gonna try that real quick
m
yea, its pretty lacking. i had been trying to use secureString.convretEncoding to get it to base64, then appendSecureString to combine it with "Basic ", but i'd only get unexpected errors. makes sense if it only supports on encoding though.
b
use of credentials key in the second example, though to my knowledge its not actually needed in their example
you only need the credentials if you use guids in the headers or body
m
i'm curious, where are you located?
b
Pacific timezone
m
california?
b
yes
m
thank you very much for your help, i'm getting a much more helpful error message now lol