So I got a suitelet where I can host my angular fi...
# suitescript
s
So I got a suitelet where I can host my angular files! The final hurdle is CORS -.-. In trying to call my restlet I get the oh so lovely CORS issue. Anyone have an idea of how to get around this? I'm in a netsuite suitelet trying to call my netsuite restlet Suitelet domain: https://{{accountId}}.app.netsuite.com/ RestletĀ  domain: https://{{accountId}}.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=1818&deploy=1
f
Suitelet calling a restlet should not trigger CORS as that is only if a browser (ClientScript) is trying to call an API
s
I am not calling it from the suitelet file. I'm calling it from the angular (html/js/client) side
b
use the internal url of the restlet
s
Can you elaborate @battk
b
your restlet has 2 urls
the normal internal url
and the external url
the internal url of the restlet is appropiate for use with an internal suitelet url
mostly because they are on the same domain
s
I'm assuming you mean clicking on this and then use that url?
I get a forbidden. please send restlet requests to ....
b
you should be able to use a relative url by itself
s
Do you have a code example I could try?
b
nope
you can try sharing what you have
s
My bad, I thought I had. This is throwing an error of "needing to be fully qualified url"
Copy code
var restletUrl = url.resolveScript({
    scriptId: 'customscript_ad_rl_query',
    deploymentId: 'customdeploy_ad_rl_query',
    returnExternalUrl: false
});
var response = <http://https.post|https.post>({
    url: restletUrl,
    body: context.request.body,
    headers: {Authorization: headers.Authorization}
});
b
using https.post means you are using netsuite as a proxy
s
what should I be using?
b
fetch or XMLHttpRequest
if you want to use N/https, you need to also get the domain
and i believe add a protocol (https://)
s
I'll try fetch! https requires me to use the oauth stuff
So, that hopefully fixes my other question. So for this one with me trying to bypass cors when calling form a client script to my restlet, is that possible?
b
its the same thing
you dont have the option of using fetch serverside
s
Not really. One has to call the suitelet, and then make the call. The other is my angular app makes the http request
b
probably need to clarify if you are talking about the serverside suitelet
or the page generated by the suitelet
or do you have some other website that is trying to use an external suitelet
s
I have a suitelet that has an inline html. That html is my angular application. The html, via javascript, is trying to call the restlet with an http request
b
you will only get cors trying to use the external url of your restlet
dont use the external url of your restlet
s
Yeah. so It may be that it's not possible to call a restlet directly from the client side script of a suitelet
b
you can call an internal url directly from the client side
s
I get the "you must call the .restlet" url
b
its a normal technique, though its usually done with another suitelet
s
so you meantioned to use fetch, but I don't see a fetch module?
its far more normal clientside to be using the browser's i/o
which is basically done using fetch or XMLHttpRequest
you can use N/https, but you have to keep in mind that you are limited in points
s
fetch will require oauth info too though right?
b
no
oauth is only if you are trying to use the external url
and you will fail at cors before you get there
if you really wanted to, you can use N/https with the external url, since N/https makes netsuite act as a proxy
you then would have to implement TBA, to add the required header
s
If fetch will do what you say, I'd much rather use that lol
To get started with fetch, is it an npm install type of thing?
b
its a browser global
s
Hmmm, I'm getting
ReferenceError: fetch is not defined [at Object.onRequest
any idea why?
Copy code
fetch('https://${AccountId}.<http://app.netsuite.com/app/site/hosting/restlet.nl?script=1818&deploy=1')|app.netsuite.com/app/site/hosting/restlet.nl?script=1818&deploy=1')>
    .then(response => {
            log.debug("response", response);
            return response.json()
        }
    )
    .then(data => log.debug(data));
b
id guess your code fragment was being run serverside
s
I'd recommend using the Angular http client.
f
yeah
url.resolveScript
and a simple http client without any authentication setting works as it should use your current user session
s
who knew! So I am able to use the "logged in path" like you mentioned @battk AND who knew that removing the authentication stuff was important. I guess I was just overwriting what netsuite already had there.
#happyDance #uglyCrying lol. Thank you everyone for your help