Chilkat Online Tools

Foxpro / Zoho CRM REST APIs / Update Pipeline

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcCode
LOCAL lcId
LOCAL lcMessage
LOCAL lcStatus
LOCAL i
LOCAL lnCount_i

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

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

* The following JSON is sent in the request body.

* {
*   "pipeline": [
*     {
*       "display_value": "{{display_value}}",
*       "default": false,
*       "maps": [
*         {
*           "display_value": "{{display_value}}",
*           "sequence_number": "{{sequence_number}}",
*           "actual_value": "{{actual_value}}",
*           "id": 123
*         },
*         {
*           "display_value": "{{display_value}}",
*           "sequence_number": "{{sequence_number}}",
*           "actual_value": "{{actual_value}}",
*           "id": 123
*         },
*         {
*           "display_value": "{{display_value}}",
*           "sequence_number": "{{sequence_number}}",
*           "actual_value": "{{actual_value}}",
*           "id": 123
*         },
*         {
*           "display_value": "{{display_value}}",
*           "sequence_number": "{{sequence_number}}",
*           "actual_value": "{{actual_value}}",
*           "id": 123
*         }
*       ]
*     }
*   ]
* }

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("pipeline[0].display_value","{{display_value}}")
loJson.UpdateBool("pipeline[0].default",0)
loJson.UpdateString("pipeline[0].maps[0].display_value","{{display_value}}")
loJson.UpdateString("pipeline[0].maps[0].sequence_number","{{sequence_number}}")
loJson.UpdateString("pipeline[0].maps[0].actual_value","{{actual_value}}")
loJson.UpdateInt("pipeline[0].maps[0].id",123)
loJson.UpdateString("pipeline[0].maps[1].display_value","{{display_value}}")
loJson.UpdateString("pipeline[0].maps[1].sequence_number","{{sequence_number}}")
loJson.UpdateString("pipeline[0].maps[1].actual_value","{{actual_value}}")
loJson.UpdateInt("pipeline[0].maps[1].id",123)
loJson.UpdateString("pipeline[0].maps[2].display_value","{{display_value}}")
loJson.UpdateString("pipeline[0].maps[2].sequence_number","{{sequence_number}}")
loJson.UpdateString("pipeline[0].maps[2].actual_value","{{actual_value}}")
loJson.UpdateInt("pipeline[0].maps[2].id",123)
loJson.UpdateString("pipeline[0].maps[3].display_value","{{display_value}}")
loJson.UpdateString("pipeline[0].maps[3].sequence_number","{{sequence_number}}")
loJson.UpdateString("pipeline[0].maps[3].actual_value","{{actual_value}}")
loJson.UpdateInt("pipeline[0].maps[3].id",123)

* Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbRequestBody = CreateObject('Chilkat.StringBuilder')
loJson.EmitSb(loSbRequestBody)

loResp = loHttp.PTextSb("PUT","https://domain.com/crm/v2.1/settings/pipeline/{{pipeline_id}}?layout_id={{layout_id}}",loSbRequestBody,"utf-8","application/json",0,0)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSbRequestBody
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    RELEASE loResp
    RELEASE loHttp
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

RELEASE loResp

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

* {
*   "pipeline": [
*     {
*       "code": "SUCCESS",
*       "details": {
*         "id": "4150868000005342021"
*       },
*       "message": "Pipeline updated",
*       "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
lnCount_i = loJResp.SizeOfArray("pipeline")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcCode = loJResp.StringOf("pipeline[i].code")
    lcId = loJResp.StringOf("pipeline[i].details.id")
    lcMessage = loJResp.StringOf("pipeline[i].message")
    lcStatus = loJResp.StringOf("pipeline[i].status")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
    "pipeline": [
        {
            "display_value": {{pipeline_name}},
            "default": false,
            "maps": [
                {
                    "display_value": {{stage_display_name}},
                    "sequence_number": {{order}},
                    "actual_value": {{stage_api_name}},
                    "id": {{stage_id}}
                },
                {
                    "display_value": {{stage_display_name}},
                    "sequence_number": {{order}},
                    "actual_value": {{stage_api_name}},
                    "id": {{stage_id}}
                },
                {
                    "display_value": {{stage_display_name}},
                    "sequence_number": {{order}},
                    "actual_value": {{stage_api_name}},
                    "id": {{stage_id}}
                },
                {
                    "display_value": {{stage_display_name}},
                    "sequence_number": {{order}},
                    "actual_value": {{stage_api_name}},
                    "id": {{stage_id}}
                }
            ]
        }
    ]
}'
https://domain.com/crm/v2.1/settings/pipeline/{{pipeline_id}}?layout_id={{layout_id}}

Postman Collection Item JSON

{
  "name": "Update Pipeline",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"pipeline\": [\n        {\n            \"display_value\": {{pipeline_name}},\n            \"default\": false,\n            \"maps\": [\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                },\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                },\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                },\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                }\n            ]\n        }\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/{{pipeline_id}}?layout_id={{layout_id}}",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "settings",
        "pipeline",
        "{{pipeline_id}}"
      ],
      "query": [
        {
          "key": "layout_id",
          "value": "{{layout_id}}"
        }
      ]
    },
    "description": "To update a pipeline in a layout."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"pipeline\": [\n        {\n            \"display_value\": \"Pipeline3\",\n            \"default\": true,\n            \"maps\": [\n                {\n                    \"sequence_number\": 1,\n                    \"id\": \"4150868000000732007\",\n                    \"display_value\": \"Closed Won\"\n                },\n                {\n                    \"sequence_number\": 2,\n                    \"id\": \"4150868000000006817\",\n                    \"display_value\": \"Closed Lost\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/4150868000005342021?layout_id=4150868000000091023",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "4150868000005342021"
          ],
          "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:01:51 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "120"
        },
        {
          "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    \"pipeline\": [\n        {\n            \"code\": \"SUCCESS\",\n            \"details\": {\n                \"id\": \"4150868000005342021\"\n            },\n            \"message\": \"Pipeline updated\",\n            \"status\": \"success\"\n        }\n    ]\n}"
    },
    {
      "name": "MANDATORY_NOT_FOUND",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"pipeline\": [\n        {\n            \"display_value\": \"Pipeline4\",\n            \"default\": true,\n            \"maps\": [\n                {\n                    \"sequence_number\": 1,\n                    \"display_value\": \"Closed Won\"\n                },\n                {\n                    \"sequence_number\": 2,\n                    \"id\": \"4150868000000006817\",\n                    \"display_value\": \"Closed Lost\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/4150868000005342021?layout_id=4150868000000091023",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "4150868000005342021"
          ],
          "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:02:44 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "166"
        },
        {
          "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    \"pipeline\": [\n        {\n            \"code\": \"MANDATORY_NOT_FOUND\",\n            \"details\": {\n                \"api_name\": \"id\",\n                \"json_path\": \"$.pipeline[0].maps[0].id\"\n            },\n            \"message\": \"required field not found\",\n            \"status\": \"error\"\n        }\n    ]\n}"
    },
    {
      "name": "INVALID_DATA (layout ID)",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"pipeline\": [\n        {\n            \"display_value\": \"Pipeline4\",\n            \"default\": true,\n            \"maps\": [\n                {\n                    \"sequence_number\": 1,\n                    \"id\": \"4150868000000732007\",\n                    \"display_value\": \"Closed Won\"\n                },\n                {\n                    \"sequence_number\": 2,\n                    \"id\": \"4150868000000006817\",\n                    \"display_value\": \"Closed Lost\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/4150868000005342021?layout_id=415086800000009102",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "4150868000005342021"
          ],
          "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:03:09 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 (pipeline ID)",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"pipeline\": [\n        {\n            \"display_value\": \"Pipeline4\",\n            \"default\": true,\n            \"maps\": [\n                {\n                    \"sequence_number\": 1,\n                    \"id\": \"4150868000000732007\",\n                    \"display_value\": \"Closed Won\"\n                },\n                {\n                    \"sequence_number\": 2,\n                    \"id\": \"4150868000000006817\",\n                    \"display_value\": \"Closed Lost\"\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/415086800000534202?layout_id=415086800000009102",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "415086800000534202"
          ],
          "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:03:25 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": "OAUTH_SCOPE_MISMATCH",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"pipeline\": [\n        {\n            \"display_value\": {{pipeline_name}},\n            \"default\": false,\n            \"maps\": [\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                },\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                },\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                },\n                {\n                    \"display_value\": {{stage_display_name}},\n                    \"sequence_number\": {{order}},\n                    \"actual_value\": {{stage_api_name}},\n                    \"id\": {{stage_id}}\n                }\n            ]\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2.1/settings/pipeline/4150868000005342021?layout_id=4150868000000091023",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "settings",
            "pipeline",
            "4150868000005342021"
          ],
          "query": [
            {
              "key": "layout_id",
              "value": "4150868000000091023"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 08:43:01 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "113"
        },
        {
          "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-Download-Options",
          "value": "noopen"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"OAUTH_SCOPE_MISMATCH\",\n    \"details\": {},\n    \"message\": \"invalid oauth scope to access this URL\",\n    \"status\": \"error\"\n}"
    }
  ]
}