The application Add Record using API illustrates the usage of the Deluge postURL task to add a new record to another Zoho Creator application. Here we use the Zoho Creator XML RPC API to add a new record. The application comprises of a dummy form "POST URL" with fields "TaskName" and "TaskDescr". When the form is submitted, a new record is added to another Zoho Creator application named "task-management" with form name "Tasks" with the values entered in the dummy form.
1. The POST method format to add a new record using the XML-RPC API is given below:
<form method="POST" action="http://creator.zoho.com/api/xml/write/apikey=[APIKEY]&ticket=[Ticket]">
<input type="hidden" name="XMLString" value="XML String in the format as specified in the Request format">
<input type="submit" value="Sumit XML String">
</form>
2. The request parameters (i.e) the application name, form name and the record values to be updated must be specified in the prescribed format:
<ZohoCreator>
<applicationlist>
<application name="applicationName">
<formlist>
<form name="formName">
<add>
<field name="fieldName"><value>fieldValue</value></field>
<field name="fieldName"><value>fieldValue</value></field>
<field name="fieldName"><options><option>Option 1</option><option>Option 2</option>
</field>
</add>
</form>
</formlist>
</application>
</applicationlist>
</ZohoCreator>
3. In this example,
- "task-management" is the name of the application to which a new record is added
- "Tasks" is the form name with field names "Task" and "Description.
- The field value input.TaskName refers to the value specified in the TaskName field of the dummy form.
- The field value input.TaskDescr refers to the value specified in the TaskDescr field of the dummy form.
"<ZohoCreator>
<applicationlist>
<application name=\"task-management\">
<formlist>
<form name=\"Tasks\">
<add>
<field name=\"Task\"><value>input.TaskName</value></field>
<field name=\"Description\"><value>input.TaskDescr</value></field>
</add>
</form>
</formlist>
</application>
</applicationlist>
</ZohoCreator>"
4. The following Deluge Script is added to the On click action of the dummy form to add a new record using the XML-RPC API. The script will be executed on click of the form button. Refer Deluge Script for the code explanation.
form Post_URL1
{
displayname = "Add Record using API"
store data in zc = false
TaskName
(
type = text
)
TaskDescr
(
type = textarea
)
actions
{
On_Click
(
type = submit
displayname = "On Click"
on click
{
mapvariable = map();
mapvariable.put("XMLString",
"<ZohoCreator>
<applicationlist><application name=\"task-management\">
<formlist>
<form name=\"Tasks\"><add><field name=\"Task\"><value>" + input.TaskName + "</value></field>
<field name=\"Description\"><value>" + input.TaskDescr + "</value></field></add>
</form>
</formlist>
</application></applicationlist>
</ZohoCreator>");
mapvariable.put("zc_ownername", "zc_help");
ResponseMapVariable = postUrl("http://creator.zoho.com/api/xml/write/apikey=1234&ticket=1234",
mapvariable,false);
);
}
)
}
}
In the Script builder we have created a map variable with the above Key and Value.
Code Explanation