I'm trying to get a Suitelet to call a RESTlet in ...
# suiteql
b
I'm trying to get a Suitelet to call a RESTlet in order to do a CSV import. I've found the documented example of how to make that call. Is hard-coding a password really the only way to do that? Doesn't seem like a great option.
w
"Starting with NetSuite 2020.2, you can use the N/https module to communicate between SuiteScript scripts, RESTlets, and SuiteTalk REST APIs without having to reauthenticate, using the https.requestRestlet(options) and https.requestSuiteTalkRest(options) methods." https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4418229131.html
👍 1
b
Aha. I hadn't found that but it looks like exactly what I need. Thanks for sharing!
Have you used this function successfully for a POST? GET works fine but it returns code 500 with a generic "contact support" error no matter what I do for a POST. There is no indication it is actually calling the restlet (according to the logs).
w
It looks like you have to add the header, otherwise it fails. I got below to work:
Copy code
var requestHeader = {
                'Content-Type': 'application/json'
            }
            var myRestletResponse = https.requestRestlet({
                body: JSON.stringify({ bodyText: 'My Restlet body' }),
                deploymentId: 'customdeploy1',
                headers: requestHeader,
                method: 'POST',
                scriptId: 2051,
            })
b
I realized this morning that I had posted this in the wrong channel (suiteql was probably the last channel I was looking at last week). I posted an updated question in the suitescript channel and had someone suggest specifying the header. I was doing almost that exact thing as your example but was not stringifying the body. The documentation says the body parameter accepts either a string or an object. I had tried a string before but without the header. The combination of the content-type and JSON.stringify just worked for me as well.
Thank you so much for the follow up.