Create a Pipeline
Purpose
To create a pipeline with various stages that a deal passes through.
Request Details
Request URL
{api-domain}/crm/{version}/settings/pipeline?layout_id={layout_id}
Header
Authorization: Zoho-oauthtoken <access_token>
Scope
scope=ZohoCRM.settings.pipeline.CREATE
Parameters
- layout_idstring, mandatory
The unique ID of the layout in which the pipeline must be created.
Sample Request
Copiedcurl "https://www.zohoapis.com/crm/v2.1/settings/pipeline?layout_id=3652397000000091023"
-X POST
-H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"
-d "@input.json"
Copied//Get instance of PipelineOperations Class
$pipelineOperations = new PipelineOperations($layoutId);
$pipelineClass = "com\\zoho\\crm\\api\\pipeline\\PipeLine";
$pipeline = new $pipelineClass();
$pipeline->setDisplayValue("Adfasfsad13");
$pickList = new PickListValue();
$pickList->setId("34770610006801");
$pickList->setSequenceNumber(1);
$pipeline->setMaps([$pickList]);
$bodyWrapper = "com\\zoho\\crm\\api\\pipeline\\BodyWrapper";
$body = new $bodyWrapper();
$body->setPipeline([$pipeline]);
//Call createPipelines method that takes BodyWrapper instance as parameter
$response = $pipelineOperations->createPipelines($body);
Copied<?php
class CreatePipelines
{
public function execute(){
$curl_pointer = curl_init();
$curl_options = array();
$parameters = array();
$parameters["layout_id"]="34770610087501";
foreach ($parameters as $key=>$value){
$url =$url.$key."=".$value."&";
}
$url = "https://www.zohoapis.com/crm/v2.1/settings/pipeline?";
$curl_options[CURLOPT_URL] =$url;
$curl_options[CURLOPT_RETURNTRANSFER] = true;
$curl_options[CURLOPT_HEADER] = 1;
$curl_options[CURLOPT_CUSTOMREQUEST] = "POST";
$requestBody=array();
$pipeline=array();
$pipelineObject=array();
$pipelineObject["display_value"]="Pipeline2";
$pipelineObject["default"]=true;
$maps=array();
$mapsObject=array();
$mapsObject["sequence_number"]=1;
$mapsObject["display_value"]="Closed Won";
$mapsObject["id"]="3652397000000006815";
array_push($maps,$mapsObject);
$mapsObject1=array();
$mapsObject1["sequence_number"]=2;
$mapsObject1["display_value"]="Closed Lost";
$mapsObject1["id"]="3652397000000006817";
array_push($maps,$mapsObject1);
$pipelineObject["maps"]=$maps;
array_push($pipeline,$pipelineObject);
$requestBody["pipeline"]=$pipeline;
$curl_options[CURLOPT_POSTFIELDS]= json_encode($requestBody);
$headersArray = array();
$headersArray[] = "Authorization". ":" . "Zoho-oauthtoken " . "1000.30f3a589XXXXXXXXXXXXXXXXXXX4077.dc5XXXXXXXXXXXXXXXXXXXee9e7c171c";
$curl_options[CURLOPT_HTTPHEADER]=$headersArray;
curl_setopt_array($curl_pointer, $curl_options);
$result = curl_exec($curl_pointer);
$responseInfo = curl_getinfo($curl_pointer);
curl_close($curl_pointer);
list ($headers, $content) = explode("\r\n\r\n", $result, 2);
if(strpos($headers," 100 Continue")!==false){
list( $headers, $content) = explode( "\r\n\r\n", $content , 2);
}
$headerArray = (explode("\r\n", $headers, 50));
$headerMap = array();
foreach ($headerArray as $key) {
if (strpos($key, ":") != false) {
$firstHalf = substr($key, 0, strpos($key, ":"));
$secondHalf = substr($key, strpos($key, ":") + 1);
$headerMap[$firstHalf] = trim($secondHalf);
}
}
$jsonResponse = json_decode($content, true);
if ($jsonResponse == null && $responseInfo['http_code'] != 204) {
list ($headers, $content) = explode("\r\n\r\n", $content, 2);
$jsonResponse = json_decode($content, true);
}
var_dump($headerMap);
var_dump($jsonResponse);
var_dump($responseInfo['http_code']);
}
}
(new CreatePipelines())->execute();
Request JSON
- display_valueString, mandatory
The name of the pipeline you want to create. This key accepts an alphanumeric value.
- mapsJSON array, mandatory
The different stages that a deal has to pass through in the sales pipeline. Thi array contains the following keys:
sequence_number - integer, mandatory - The order in which the stage must be displayed. If the value of this key is "1", then this stage will be displayed first.
id - string, mandatory - The unique ID of the stage. Use the Fields Metadata API to obtain the unique ID of the field.
Sample Input
Copied{
"pipeline": [
{
"display_value": "Pipeline2",
"default": true,
"maps": [
{
"sequence_number": 1,
"id": "3652397000000006815",
"display_value": "Closed Won"
},
{
"sequence_number": 2,
"id": "3652397000000006817",
"display_value": "Closed Lost"
}
]
}
]
}
Possible Errors
- MANDATORY_NOT_FOUNDHTTP 400
You have not included the key "display_value" (name of the pipeline) in the input.
Resolution: "display_value" is a mandatory key in the input. - INVALID_DATAHTTP 400
The ID of the stage in the "maps" object is invalid.
Resolution: Use the Fields Metadata API to obtain the unique IDs of the stages. - DUPLICATE_DATAHTTP 400
A pipeline with the same name already exists.
Resolution: The name of the pipeline must be unique. - REQUIRED_PARAM_MISSINGHTTP 400
You have not included the mandatory parameter "layout_id" in your request.
Resolution: Specify valid layout ID in the request.
Sample Response
Copied{
"pipeline": [
{
"code": "SUCCESS",
"details": {
"id": "3652397000003712004"
},
"message": "Pipeline created",
"status": "success"
}
]
}