Creator Help

Post URL

Table of Contentsup

Post URL

The post data Deluge task corresponds to a HTTP POST request. It is normally supported by services to perform write operations like adding or updating data.

Syntax

a. To get a simple response with only the response content as String:

<string-variable> = postUrl(<url string>,<map-variable>,true)

where,

<string-variable> - the name of the string variable to hold the response content in string format.
<url string> - the URL to be accessed, for example, "http://creator.zoho.com"
<map-variable> - the map variable that holds the request values as a key-value pair in the specified format.

b. To get a detailed response that returns the response code (http status code) and response content as a key-value pair.

<map-variable> = postUrl(<url string>,<map-variable>,false)

where,

<map-variable> - the name of the map variable to hold the response code and response content.
<url string> - the URL to be accessed, for example, "http://creator.zoho.com"
<map-variable> - the map variable that holds the request values as a key-value pair in the specified format.

c. To post header information along with request, the information need to passed for third argument as map-variable

<String/Map-variable> = postUrl(<url string>,<request map-variable>,<header map variable>, <boolean isSimpleResponse>)

where,

<map-variable>- the name of the map variable to hold the response code and response content.
<url string>- the URL to be accessed, for example, "http://creator.zoho.com"
<request map-variable>- the map variable that holds the request values as a key-value pair in the specified format.
<header map-variable>- the map variable that holds the header values as a key-value pair in the specified format.
<isSimpleResponse>- optional boolean value, true for simple(string) and false for detailed(map) response. The default value is true.

d. To directly write content to the body of POST request (eg, inserting an entry using GDATA protocol).

<String/Map-variable> = postUrl(<url string>,<request string-variable>,<header map variable>, <boolean isSimpleResponse>)

where,

<map-variable>- the name of the map variable to hold the response code and response content.
<url string>- the URL to be accessed, for example, "http://creator.zoho.com"
<request string-variable>- the string variable holding the content that needs to be written in the body of POST request.
<header map-variable> - the map variable that holds the header values as a key-value pair in the specified format.
<isSimpleResponse> - optional boolean value, true for simple(string) and false for detailed(map) response. The default value is true.

Note:

  • You can use the encodeURL() function to encode the url string.

Syntax to get response code and response text:

map.get("responseCode"); // returns the HTTP response status code
map.get("responseText");

If the response text is of type XML, the executeXPath statement can be used to select nodes from the document. If the response text is of type JSON, it an be converted to XML.

Using Script Builder

To add the post url task in Script Builder,

  1. Drag-n-drop the Web Data - post url from the left-side task tree.
  2. Click on Edit to display the Edit dialog.
  3. Specify the URL string of the external website
  4. Specify the request map variable that holds the Post request parameters ( in the format specified by the external APIs)
  5. Select "Simple Response" to get only the response content as a string or the "Detailed Response" to get the response code and response content as a key-value pair.
  6. Click Done to add the value to the script editor.

Example

Lets say we have an application named Application A with a form named Form A with fields "Name1" , "Email1" and "Phone1". Similarly we have an application named Application B with a form named Form B with fields "Name2", "Email2" and "Phone2". When a record is added to Form A, the same record needs to be added automatically to Form B. To achieve this add the following code, in the On Add -> On Success block of Form A.

myMap = map();
myMap.put("authtoken", "<your API key>");
myMap.put("scope", "creatorapi");
myMap.put("Name2", input.Name1);
myMap.put("Email2", input.Email1);
myMap.put("Phone2", input.Phone1);
resp = postUrl("https://creator.zoho.com/api/<appowner>/json/ApplicationB/form/FormB/record/add/", myMap);

where,
<your API key> is your authtoken.  
<appowner> is the app owner name. 
ApplicationB is the link name of the application to which the records need to be added automatically.
FormB is the link name of the form to which the records need to be added automatically.
resp holds the response content

Related links

Add Record using API | Read Contact information from Google Contacts API

Top