Separate from my above question... I keep trying t...
# suitescript
s
Separate from my above question... I keep trying to call a restlet from a suitelet, but getting 1) has to be a fully qualified url and 2) 401. Is there a way to call a restlet from a suitelet without using the externalUrl?
f
you can use
N/url
resolveScript to find the internal URL to your restlet by scriptid/deploymentid and using
N/https
should take care of authentication in my experience.
s
this is the code and it gives me the "must be a fully qualified url" error.
Copy code
var restletUrl = url.resolveScript({
    params:{Authorization: context.request.headers.Authorization},
    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
});
m
url.resolveScript()
only resolves a relative url, you'll also need to add the domain to that before using it with
<http://https.post|https.post>()
. I'd suggest using
url.resolveDomain()
for getting the domain, but you can also hard-code it if you're only running this script in one account (or at least for a quick test).
s
It's still giving me an invalid login attempt and wants the oauth info. Is there not a way around that?
m
It seems like you've gotten something figured out on the other thread, but just as an extra note, if you're making the call in a server script, you could use
https.requestRestlet()
.
s
Possibly. He's mentioned to use fetch, but I feel I'm going to have the same issue.... it's still a call I have to add authentication
m
I've never used a Restlet without authentication so I can't help on that part unfortunately. Is there a reason you're using a Restlet at all that point though? If you're calling client-side, a Suitelet should get you to the same end (i.e. you can call without authentication) and would avoid the weirdness of authenticating to a Restlet.
s
True. Ideally I'd like to make a call to the restlet from my angular code. Main reason for the restlet is I have a re-usable restlet that allows me to query data inside of netsuite, so I was hoping to do that. Really I need to be able to make this call from the angular embedded code
That way I can actually use the data that comes back. I don't know how to get it from the suitelet to the embedded code
f
@screnshaw try remove
params
and
returnExternalUrl
from resolveUrl
I’ve never had to add that for calls from within netsuite
and you can just move the general query code into a separate module. Then your suitelet can call the general library code and the restlet can load it too
and you don’t need the extra cost of an http call from within your suitelet