httpsnetsuiteclientscript

Netsuite client script https post request unexpected error


I have a User Event and Client Script for my Netsuite system. I added a button on a transaction page. This code works on the User Event beforeLoad function, but for my client script button press function I get an error: Unexpected error and am not sure why it runs fine on one but not the other? I have put in an example url and example data so it is not the exact code.

thank you

    var requestData = {"externUserId":"Tom","externAppName":"Netsuite","externAppScreenTitle":"Bill","Setting":"true"};
    
    requestData = JSON.stringify(requestData);

    var headerObj = new Array();
    headerObj['Content-Type'] = 'application/json';
    headerObj['Accept'] = 'application/json';
    
    var response = https.post({
        url: 'https://test.zzzz.com/myexample/api/SetVisible',
        headers: headerObj,
        body: requestData
    });

Solution

  • Netsuite doesn't expect an array as headers. Your basic code looks correct so try:

        var requestData = {"externUserId":"Tom","externAppName":"Netsuite","externAppScreenTitle":"Bill","Setting":"true"};
        
        requestData = JSON.stringify(requestData);
    
        var headerObj = {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        };
        
        var response = https.post({
            url: 'https://test.zzzz.com/myexample/api/SetVisible',
            headers: headerObj,
            body: requestData
        });