Chilkat Online Tools

phpExt / Zoho CRM REST APIs / Transfer and Delete Pipeline

Back to Collection Items

<?php

include("chilkat_9_5_0.php");

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$http = new CkHttp();

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "transfer_pipeline": [
//     {
//       "pipeline": {
//         "from": "{{from}}",
//         "to": "{{to}}"
//       },
//       "stages": [
//         {
//           "from": "{{from}}",
//           "to": "{{to}}"
//         }
//       ]
//     }
//   ]
// }

$json = new CkJsonObject();
$json->UpdateString('transfer_pipeline[0].pipeline.from','{{from}}');
$json->UpdateString('transfer_pipeline[0].pipeline.to','{{to}}');
$json->UpdateString('transfer_pipeline[0].stages[0].from','{{from}}');
$json->UpdateString('transfer_pipeline[0].stages[0].to','{{to}}');

// Adds the "Authorization: Bearer <access_token>" header.
$http->put_AuthToken('<access_token>');

// resp is a CkHttpResponse
$resp = $http->PostJson3('https://domain.com/crm/v2.1/settings/pipeline/actions/transfer?layout_id={{layout_id}}','application/json',$json);
if ($http->get_LastMethodSuccess() == false) {
    print $http->lastErrorText() . "\n";
    exit;
}

$sbResponseBody = new CkStringBuilder();
$resp->GetBodySb($sbResponseBody);

$jResp = new CkJsonObject();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(false);

print 'Response Body:' . "\n";
print $jResp->emit() . "\n";

$respStatusCode = $resp->get_StatusCode();
print 'Response Status Code = ' . $respStatusCode . "\n";
if ($respStatusCode >= 400) {
    print 'Response Header:' . "\n";
    print $resp->header() . "\n";
    print 'Failed.' . "\n";

    exit;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "transfer_pipeline": [
//     {
//       "code": "SUCCESS",
//       "details": {
//         "job_id": "4150868000005342033"
//       },
//       "message": "transfer pipeline scheduled successfully",
//       "status": "success"
//     }
//   ]
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

$i = 0;
$count_i = $jResp->SizeOfArray('transfer_pipeline');
while ($i < $count_i) {
    $jResp->put_I($i);
    $code = $jResp->stringOf('transfer_pipeline[i].code');
    $Job_id = $jResp->stringOf('transfer_pipeline[i].details.job_id');
    $message = $jResp->stringOf('transfer_pipeline[i].message');
    $status = $jResp->stringOf('transfer_pipeline[i].status');
    $i = $i + 1;
}


?>

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "transfer_pipeline": [
        {
            "pipeline": {
                "from": {{pipeline_id_to_transfer}},
                "to": {{pipeline_id_to_be_transferred_to}}
            },
            "stages": [
                {
                    "from": {{pipeline_id_to_transfer}},
                    "to": {{pipeline_id_to_be_transferred_to}}
                }
            ]
        }
    ]
}'
https://domain.com/crm/v2.1/settings/pipeline/actions/transfer?layout_id={{layout_id}}

Postman Collection Item JSON

{
  "name": "Transfer and Delete Pipeline",
  "request": {
    "auth": {
      "type": "bearer"
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"transfer_pipeline\": [\n        {\n            \"pipeline\": {\n                \"from\": {{pipeline_id_to_transfer}},\n                \"to\": {{pipeline_id_to_be_transferred_to}}\n            },\n            \"stages\": [\n                {\n                    \"from\": {{pipeline_id_to_transfer}},\n                    \"to\": {{pipeline_id_to_be_transferred_to}}\n                }\n            ]\n        }\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/actions/transfer?layout_id={{layout_id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "settings",
        "pipeline",
        "actions",
        "transfer"
      ],
      "query": [
        {
          "key": "layout_id",
          "value": "{{layout_id}}"
        }
      ]
    },
    "description": "To delete a pipeline and transfer the associated stages to another pipeline."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"transfer_pipeline\": [\n        {\n            \"pipeline\": {\n                \"from\": \"4150868000001874009\",\n                \"to\": \"4150868000001874016\"\n            },\n            \"stages\": [\n                {\n                    \"from\": \"4150868000000006801\",\n                    \"to\": \"4150868000000006803\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/actions/transfer?layout_id=4150868000000091023",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "actions",
            "transfer"
          ],
          "query": [
            {
              "key": "layout_id",
              "value": "4150868000000091023"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 11:07:25 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "157"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-10T17:05:19+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4016246"
        },
        {
          "key": "clientsubVersion",
          "value": "59f8474ad0046d6a2f6204e0448818d0"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"transfer_pipeline\": [\n        {\n            \"code\": \"SUCCESS\",\n            \"details\": {\n                \"job_id\": \"4150868000005342033\"\n            },\n            \"message\": \"transfer pipeline scheduled successfully\",\n            \"status\": \"success\"\n        }\n    ]\n}"
    },
    {
      "name": "REQUIRED_PARAM_MISSING",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"transfer_pipeline\": [\n        {\n            \"pipeline\": {\n                \"from\": \"4150868000001874009\",\n                \"to\": \"4150868000001874016\"\n            },\n            \"stages\": [\n                {\n                    \"from\": \"4150868000000006801\",\n                    \"to\": \"4150868000000006803\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/actions/transfer",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "actions",
            "transfer"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 11:07:47 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "136"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"REQUIRED_PARAM_MISSING\",\n    \"details\": {\n        \"param\": \"layout_id\"\n    },\n    \"message\": \"One of the expected parameter is missing\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "MANDATORY_NOT_FOUND",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"transfer_pipeline\": [\n        {\n            \"pipeline\": {\n                \"to\": \"4150868000001874016\"\n            },\n            \"stages\": [\n                {\n                    \"from\": \"4150868000000006801\",\n                    \"to\": \"4150868000000006803\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/actions/transfer?layout_id=4150868000000091023",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "actions",
            "transfer"
          ],
          "query": [
            {
              "key": "layout_id",
              "value": "4150868000000091023"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 11:08:07 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "192"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-10T17:05:19+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4016246"
        },
        {
          "key": "clientsubVersion",
          "value": "59f8474ad0046d6a2f6204e0448818d0"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"transfer_pipeline\": [\n        {\n            \"code\": \"MANDATORY_NOT_FOUND\",\n            \"details\": {\n                \"api_name\": \"from\",\n                \"json_path\": \"$.transfer_pipeline[0].pipeline[0].from\"\n            },\n            \"message\": \"Required field not found\",\n            \"status\": \"error\"\n        }\n    ]\n}"
    },
    {
      "name": "INVALID_DATA (layout ID)",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"transfer_pipeline\": [\n        {\n            \"pipeline\": {\n                \"from\": \"4150868000001874009\",\n                \"to\": \"4150868000001874016\"\n            },\n            \"stages\": [\n                {\n                    \"from\": \"4150868000000006801\",\n                    \"to\": \"4150868000000006803\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/actions/transfer?layout_id=415086800000009102",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "actions",
            "transfer"
          ],
          "query": [
            {
              "key": "layout_id",
              "value": "415086800000009102"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 11:08:27 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "107"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-10T17:05:19+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4016246"
        },
        {
          "key": "clientsubVersion",
          "value": "59f8474ad0046d6a2f6204e0448818d0"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_DATA\",\n    \"details\": {\n        \"param_name\": \"layout_id\"\n    },\n    \"message\": \"Invalid layoutid\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_DATA (request input)",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"transfer_pipeline\": [\n        {\n            \"pipeline\": {\n                \"from\": \"415086800000187400\",\n                \"to\": \"4150868000001874016\"\n            },\n            \"stages\": [\n                {\n                    \"from\": \"4150868000000006801\",\n                    \"to\": \"4150868000000006803\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/actions/transfer?layout_id=4150868000000091023",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "actions",
            "transfer"
          ],
          "query": [
            {
              "key": "layout_id",
              "value": "4150868000000091023"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 11:08:51 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "176"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-10T17:05:19+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4016246"
        },
        {
          "key": "clientsubVersion",
          "value": "59f8474ad0046d6a2f6204e0448818d0"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"transfer_pipeline\": [\n        {\n            \"code\": \"INVALID_DATA\",\n            \"details\": {\n                \"api_name\": \"from\",\n                \"json_path\": \"$.transfer_pipeline[0].pipeline[0].from\"\n            },\n            \"message\": \"Invalid from id\",\n            \"status\": \"error\"\n        }\n    ]\n}"
    }
  ]
}