Data sending format in Standalone Functions - deptster/deptster.github.io GitHub Wiki

Send data from widget into OAuth2 function developed in Node JS:

Widget Code:

function onSubmit () {
    var displayResult = document.getElementById("displayResult");

    // Execute PeLocal Function
    var func_name = "functionName"; // this is the link name of the function https://sandbox.zohoapis.in/crm/v2/functions/[functionName]/actions/execute?auth_type=oauth
    // this is how you send arguments into that function:
    var req_data ={
        "arguments": JSON.stringify({
            "recId" : recordId,
            "sendType" : sendType.value,
            "tempName" : templateDropdown.options[templateDropdown.selectedIndex].text
        })
    };
    console.log(req_data);
    ZOHO.CRM.FUNCTIONS.execute(func_name, req_data)
    .then(function(data){
        console.log(data)
        if(data.code == "success") {
            output = JSON.parse(data.details.output);
            // output.message will have the message that you are returning from the function i.e. basicIO.write(message);
            if(output.message == "Request failed with status code 401") {
                displayResult.innerHTML = "Request Failed, Check Function";
            } else {
                displayResult.innerHTML = "Success <br>" + output.message;
            }
        } else {
            displayResult.innerHTML = data.code;
        }
    })
}

Code inside the Node JS function:

module.exports = async function (context, basicIO) {
    // To get the complete Request Object
    var requestObject = basicIO.getParameter("request_object");
    // To get the Arguments from the Request Object
    requestBody = JSON.parse(requestObject.params.arguments);
    // getting the actual value of the key like this
    requestBody.variable1;
    requestBody.variable2;
    // giving the output of the function
    basicIO.write(requestBody.variable2);
}