For this tutorial in video form, click here
In this article, we’re going to show you how to make serverless custom functions in Zoho CRM.
We’ll start off by clicking setup in our CRM (it’s the tool icon in the top right corner). Then, we’ll go to Developer Space>Functions.
What function are we going to create? Here is some context:
In some cases you want another program outside Zoho CRM to be able to update CRM data. You can do that using the APIs SDKs, but they can be quite fiddly to get working. In fact, it’s much easier to do it by making a custom serverless function. Let’s do that by clicking +New Function in the top right.
From here, you can make it a standalone and call it whatever you want, like so:
Once your function is created, click “edit arguments” at the top and add the following:
For this example, we’ll make a really simple function that just returns inputted data:
But it doesn’t have to be that simple. You could create an add record function like this:
Now, we’ll save this function by clicking the blue “save” button.
Enabling As An API
Once you’ve got it saved, head back into the functions list, and sort it by standalone functions.
Next, click the 3 dots that appear as you hover above your new function, and click “REST API”.
Turn on API key and copy the contents before saving the page.
We can use a tool like Insomnia or Postman in order to be able to send data to our API. Let’s try Insomnia. We’ll make a new request as POST and then select “Body”.
Here, we can paste what we copied at the top.
For the body, we’re going to choose “Multipart Form”.
Next, we’ll tell it what arguments we are sending.
Now, click “send” in the top right. Here is what our output looks like back:
If we look in the CRM, we can see that it has made a new lead.
Calling With Code
To do this, we have to make a form data object. This is the same what we did here in Insomnia using Multipart Form in coding.
Consider the following code:
Notice how we get the data and stringify it (which is basically what we did earlier in Insomnia). You’ll also notice that we’re URL encoding the value. If we send something a bit more complicated than our simple example, (especially with less common characters), Zoho will restrict you.
To get around this, you have to URL encode the data. In the Deluge Script, you have to then URL decode it. Let’s say we make it a string:
We’ll then have to decode it in Deluge, like on line 1:
Let’s use an online URL encoder to encode the data we want to send.
We can then copy and paste it into the empty quote like below:
As you can see, it’ll come out looking the same:
We recommend always encoding your URL when you do a serverless custom function. Otherwise, you could risk unexpected results that are painful to debug.
Let’s go back to the TypeScript code.
Notice how we’re making sure that every argument being passed gets URL encoded. Then, we’re turning that into a string, making form data and placing all of that data in connected as the value for the arguments form property.
Once we’ve done that we can send it. In our case, we’re using Axios.
We make sure that here you can see how the URL is being passed, using the API key that you get from the URL. Then there’s a little bit here that is able to pull out the output of the function.