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(
 'authtoken' => 'AUTHTOKEN',
 'index' => 1,
 'range' => 1,
 'status' => 'active'
 );
 $request_url .= '?' . http_build_query($request_parameters);
 }
if ($method_name == 'POST')
 {
 $request_parameters = array(
 'authtoken' => 'AUTHTOKEN',
 '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]/';
 $request_parameters = array(
 'authtoken' => 'AUTHTOKEN'
 );
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
 $request_url .= '?' . http_build_query($request_parameters);
 }
/* Here you can set the Response Content Type */
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('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 Authtoken
 authtoken = AUTHTOKEN;
#Set the URL and Parameters to GET, POST and DELETE using Request Method

url = ""; params = ""; r = "";
 if method=="GET":
 url = "https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/tasks/"
 params = {"authtoken":authtoken, "index":1, "range":3}
 r = requests.get(url, params=params);
 elif method=="POST":
 url = "https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/tasks/"
 params = {"authtoken":authtoken, "name":"Client Call"}
 r = requests.post(url, params=params);
 elif method=="DELETE":
 url = "https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/tasks/[TASKID]/"
 params = {"authtoken":authtoken}
 r = requests.delete(url, params=params);
#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 authtoken = AUTHTOKEN;
 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 = "authtoken=" + authtoken + "&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 = "authtoken=" + authtoken + "&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))
 {
 parameters = "authtoken=" + authtoken;
url = new URL("https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/
[PROJECTID]/logs/[LOGID]/?" + parameters);
 request = (HttpURLConnection) url.openConnection();
 request.setRequestMethod("DELETE");
 }
// add request header
 request.setRequestProperty("Accept", "application/json");
 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();
 }
 }
 }
 }