What's the trick to sending a post request to a su...
# suitescript
c
What's the trick to sending a post request to a suitelet from a user event script? I keep getting a "Notice: You must login" page as a response.
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType UserEventScript
 */
define(['N/url', 'N/https'],
    function (url, https) {

        function afterSubmit(context) {
            const suiteletUrl = url.resolveScript({
                scriptId: 'customscript_komet_address_update_sl',
                deploymentId: 'customdeploy1'
            });
            const domain = url.resolveDomain({
                hostType: url.HostType.APPLICATION
            });

            const payload = {
                testKey: 'testVal'
            }

            let response = <http://https.post|https.post>({
                url: 'https://' + domain + suiteletUrl,
                body: JSON.stringify(payload),
                headers: { 'Content-Type': 'application/json' }
            });

            log.debug({ title: 'suiteletUrl', details: 'https://' + domain + suiteletUrl });

            log.debug({
                title: 'Suitelet Response',
                details: response.body
            });
        }

        return {
            afterSubmit: afterSubmit
        };
    }
);
n
In theory you would mark the SL “Available without login” but that’s not great for security. What are you trying to achieve?
l
try to use this function: https.requestSuitelet
🙌 1
😮 1
☝️ 1
c
That did it. Thank you!