I am trying to post to an external url from suitel...
# suitescript
m
I am trying to post to an external url from suitelet. I have double checked the URL, and I managed to test it using Postman, and it works. Please help. Here is the code that is causing an issue:
Copy code
let response = <http://https.post|https.post>({
                url: urlDomain,
                body: postString,
                headers: {
                    'Content-Type': 'application/json',
                    "Authorization": secStringBasicAuthHeader
                }
            });
I am getting the following error: Notice {"type":"error.SuiteScriptError","name":"INVALID_DOMAIN","message":"Invalid domain.","id":"","stack":["Error\n at Object.onRequest (/SuiteScripts/Atradius/Suitelet.js7634)"],"cause":{"type":"internal error","code":"INVALID_DOMAIN","details":"Invalid domain.","userEvent":null,"stackTrace":["Error\n at Object.onRequest (/SuiteScripts/Atradius/Suitelet.js7634)"],"notifyOff":false},"notifyOff":false,"userFacing":true}
s
Would probably need to see what you are putting in "urlDomain" but the message seems to think the domain is "id" and does not like that.
m
s
2 things to try. 1. test without the variable. Use a "https://api-uat.atradius.com/authenticate/v2/tokens" instead and see if that works 2. push the urlDomain variable to debug log just before the https send and see if it still contains what you expect
m
@Scot Sunnergren Thanks
m
It looks like you're using API secrets in your headers. These can be restricted to certain outgoing domains. It looks like the domain your request is going to is not approved for this particular API secret.
s
ahhh.. so posting to a domain that restricts authentication may not accept ""Authorization": secStringBasicAuthHeader" ???
m
When you look at the API secrets in NetSuite, Setup > Company > API Secrets, each secret can be restricted for use for only certain outgoing domains. If you're trying to use a secret that is not authorized for that domain, you get the "invalid domain" error message. The domain must match exactly, if I remember correctly, so atradius.com does not match api-uat.atradius.com.
the reference to secStringBasicAuthHeader looks like you have a secure string using an API secret.
s
oh... I haven't used the API Secrets table for hitting external apis... probably should look at it.
m
I have just found the issue. The encoding script from SuiteAnswer is not producing the correct base 64. The below snippet works:
Copy code
// Create BASE-64 encoded name:password pair
    let base64 = encode.convert({
        string: `${nameToken}:${passwordToken}`,
        inputEncoding: encode.Encoding.UTF_8,
        outputEncoding: encode.Encoding.BASE_64
    });