'NetSuite SuiteScript connection via rapidapi

I am having issues using RapidApi within NetSuite. Has anyone done this before?

headersObj = [
    {
        name:"x-rapidapi-host",
        value:"hostishere"
    },
    {
        name:"x-rapidapi-key",
        value:"keyishere"
    }
];

response = https.request({
    method: https.Method.GET,
    url: "MyURLishere",
    headers: headersObj
});

I get the following return:

error 400 message: Invalid API key. Go to https:docs.rapidapi.com/docs/keys for more info.

The API key is correct having tested through postman.



Solution 1:[1]

If you are making the call from within Netsuite you'd need to use their https library:

define(["N/https"], function(http){
    headersObj = [{ name:"x-rapidapi-host", value:"hostishere" }, { name:"x-rapidapi-key", value:"keyishere" }];
    var resp = http.get({url:'your url', headers:headersObj});
    // do something
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bknights