Examples

Examples

 PHP Example

     PHP Example using Projects

<?php
/* Set the Request Url (without Parameters) here */
 $request_url = 'https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/';
/* Which Request Method do I want to use ?
 GET, POST or DELETE */
 $method_name = 'GET';
$ch = curl_init();
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
/* Here you can set all Parameters based on your method_name */
 if ($method_name == 'GET')
 {
 $request_parameters = array(
 'index' => 1,
 'range' => 1,
 'status' => 'active'
 );
 $request_url .= '?' . http_build_query($request_parameters);
 }
if ($method_name == 'POST')
 {
 $request_parameters = array(
 'name' =>'Warehouse ledger',
 'description' => 'ledger balance of stocks',
 );
 curl_setopt($ch, CURLOPT_POST, TRUE);
 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
 }
if ($method_name == 'DELETE')
 {
 $request_url = 'https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/';
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
 }
/* Here you can set authorization token and response Content Type  */
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Zoho-oauthtoken <YOUR_ACCESS_TOKEN>','Accept: application/json'));
/* Let's give the Request Url to Curl */
 curl_setopt($ch, CURLOPT_URL, $request_url);
/*
 Yes we want to get the Response Header
 (it will be mixed with the response body but we'll separate that after)
 */
 curl_setopt($ch, CURLOPT_HEADER, TRUE);
/* Allows Curl to connect to an API server through HTTPS */
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/* Let's get the Response ! */
 $response = curl_exec($ch);
/* We need to get Curl infos for the http_code */
 $response_info = curl_getinfo($ch);
/* Don't forget to close Curl */
 curl_close($ch);
/* Here we get the Response Body */
 $response_body = substr($response, $response_info['header_size']);
// Response HTTP Status Code
 echo "Response HTTP Status Code : ";
 echo $response_info['http_code'];
echo "\n";
// Response Body
 echo "Response Body : ";
 echo $response_body;
 ?>

 Python Example

     Python Example using Task Module

#Begin by importing the "requests" module

import requests
#Set the Request Method
 method = "GET";
#Set the headers 
 headers = {'Authorization': 'Zoho-oauthtoken <YOUR_ACCESS_TOKEN>'}
#Set the URL and Parameters to GET, POST and DELETE using Request Method
url = ""; params = ""; r = ""; files = "";
 if method=="GET":
 url = "https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/tasks/"
 params = {"index":1, "range":3}
 r = requests.get(url, params=params, headers=headers);
 elif method=="POST":
 url = "https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/tasks/"
 params = {"name":"Client Call"}
#To attach files,if any
 files = {"uploaddoc": open("samplefile.jpg", "rb")}
 r = requests.post(url, params=params, headers=headers, files=files);
 elif method=="DELETE":
 url = "https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/tasks/[TASKID]/"
 r = requests.delete(url, headers=headers);
#Response HTTP Status Code
 print "Response HTTP Status Code : ", r.status_code
#Response Body
 print "Response Body : ", r.content

 Java Example

     Java Example using Timesheet Module

/* * java import */
import java.net.HttpURLConnection;
 import java.net.URL;
 import java.io.*;
class TimesheetDemo
 {
 public static void main(String[] args)
 {
 URL url;
 HttpURLConnection request = null;
 String method = "GET";
 String parameters = "";
 try
 {
/*
 * Set the URL and Parameters to create connection
 * Set Request Method (GET, POST or DELETE)
 */
if("GET".equals(method))
 {
 parameters = "&users_list=all&view_type=week&date=
 05-11-2014&bill_status=All&component_type=general";
url = new URL("https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/
[PROJECTID]/logs/?" + parameters);
 request = (HttpURLConnection) url.openConnection();
 request.setRequestMethod("GET");
 }
 else if("POST".equals(method))
 {
 parameters = "&name=Registration_Document_33A&date=
 05-14-2014&bill_status=Billable&hours=02:20";
url = new URL("https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/
[PROJECTID]/logs/?" + parameters);
 request = (HttpURLConnection) url.openConnection();
 request.setRequestMethod("POST");
 }
 else if("DELETE".equals(method))
 {
url = new URL("https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/
[PROJECTID]/logs/[LOGID]/?");
 request = (HttpURLConnection) url.openConnection();
 request.setRequestMethod("DELETE");
 }
// add request header
 request.setRequestProperty("Accept", "application/json");
 request.setRequestProperty("Authorization", "Zoho-oauthtoken <YOUR_ACCESS_TOKEN>");
 request.setDoOutput(true);
 request.setDoInput(true);
request.connect();
// Get Response
 BufferedReader bf = new BufferedReader(new InputStreamReader(request.getInputStream()));
 String line;
 StringBuffer response = new StringBuffer(); 
 while((line = bf.readLine())!=null) {
 response.append(line);
 response.append('\r');
 }
 bf.close();
// Response HTTP Status Code
 System.out.println("Response HTTP Status Code : " + request.getResponseCode());
// Response Body
 System.out.println("Response Body : " + response.toString());
 }
 catch(Exception e)
 {
 e.printStackTrace();
 }
 finally
 {
 if(request!=null)
 {
 request.disconnect();
 }
 }
 }
 }

 Deluge Example

Deluge Example

The following example creates a subtask for a specific task by performing an API call on Create Subtask API using the invokeUrl Deluge task. The IDs (portal ID, project ID and task ID) required for performing this function are fetched using their respective integration tasks.

// Fetch portal ID of the first portal
first_portal_id = zoho.projects.getPortals().get("portals").get(0).get("id");
// Fetch project ID of the first project
first_project_id = zoho.projects.getProjectDetails(first_portal_id).get(0).get("id");
// Fetch task ID of the first task
first_task_id = zoho.projects.getRecords(first_portal_id, first_project_id,"tasks").get("tasks").get(0).get("id") ;
// Construct map to hold the API params
params_map = Map();
params_map.put("name","Subtask 4");
params_map.put("start_date", "01-04-2020");
params_map.put("start_date", "01-05-2020");
params_map.put("priority", "High");
params_map.put("description", "Subtask 4 description");

//Execute invoke URL task to call the required API
response = invokeurl
[
	url: "https://projectsapi.zoho.com/restapi/portal/"+first_portal_id+"/projects/"+first_project_id+"/tasks/"+first_task_id+"/subtasks/"
	type: POST
	parameters: params_map
	connection : projects_connection

];
info response;

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohoprojects.com