Chilkat Online Tools

Python / Zoho CRM REST APIs / Merge Tags

Back to Collection Items

import sys
import chilkat

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

http = chilkat.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.

# {
#   "tags": [
#     {
#       "conflict_id": "{{id of the tag which you want to merge}}"
#     }
#   ]
# }

json = chilkat.CkJsonObject()
json.UpdateString("tags[0].conflict_id","{{id of the tag which you want to merge}}")

# Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>")

# resp is a CkHttpResponse
resp = http.PostJson3("https://domain.com/crm/v2/settings/tags/{{tag_id}}/actions/merge","application/json",json)
if (http.get_LastMethodSuccess() == False):
    print(http.lastErrorText())
    sys.exit()

sbResponseBody = chilkat.CkStringBuilder()
resp.GetBodySb(sbResponseBody)

jResp = chilkat.CkJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.put_EmitCompact(False)

print("Response Body:")
print(jResp.emit())

respStatusCode = resp.get_StatusCode()
print("Response Status Code = " + str(respStatusCode))
if (respStatusCode >= 400):
    print("Response Header:")
    print(resp.header())
    print("Failed.")

    sys.exit()

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

# {
#   "tags": [
#     {
#       "code": "SUCCESS",
#       "details": {
#         "created_time": "2021-05-07T12:38:01+00:00",
#         "modified_time": "2021-05-12T06:47:47+00:00",
#         "modified_by": {
#           "name": "Patricia Boyle",
#           "id": "738964000000291009"
#         },
#         "id": "738964000002130340",
#         "created_by": {
#           "name": "Patricia Boyle",
#           "id": "738964000000291009"
#         }
#       },
#       "message": "tags merged 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("tags")
while i < count_i :
    jResp.put_I(i)
    code = jResp.stringOf("tags[i].code")
    Created_time = jResp.stringOf("tags[i].details.created_time")
    Modified_time = jResp.stringOf("tags[i].details.modified_time")
    Name = jResp.stringOf("tags[i].details.modified_by.name")
    Id = jResp.stringOf("tags[i].details.modified_by.id")
    detailsId = jResp.stringOf("tags[i].details.id")
    Created_byName = jResp.stringOf("tags[i].details.created_by.name")
    Created_byId = jResp.stringOf("tags[i].details.created_by.id")
    message = jResp.stringOf("tags[i].message")
    status = jResp.stringOf("tags[i].status")
    i = i + 1

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "tags": [
       {
            "conflict_id": "{{id of the tag which you want to merge}}"
        }
    ]
}'
https://domain.com/crm/v2/settings/tags/{{tag_id}}/actions/merge

Postman Collection Item JSON

{
  "name": "Merge Tags",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"tags\": [\n       {\n            \"conflict_id\": \"{{id of the tag which you want to merge}}\"\n        }\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2/settings/tags/{{tag_id}}/actions/merge",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2",
        "settings",
        "tags",
        "{{tag_id}}",
        "actions",
        "merge"
      ]
    },
    "description": "To merge tags and put all the records under the two tags into a single tag."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"tags\": [\n       {\n            \"conflict_id\": \"738964000002130340\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/tags/738964000002130339/actions/merge",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "tags",
            "738964000002130339",
            "actions",
            "merge"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:47:47 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "341"
        },
        {
          "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-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-12T07:15:06+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4027076"
        },
        {
          "key": "clientsubVersion",
          "value": "748ecbe82ec7e144b66ee25f264bbd88"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"tags\": [\n        {\n            \"code\": \"SUCCESS\",\n            \"details\": {\n                \"created_time\": \"2021-05-07T12:38:01+00:00\",\n                \"modified_time\": \"2021-05-12T06:47:47+00:00\",\n                \"modified_by\": {\n                    \"name\": \"Patricia Boyle\",\n                    \"id\": \"738964000000291009\"\n                },\n                \"id\": \"738964000002130340\",\n                \"created_by\": {\n                    \"name\": \"Patricia Boyle\",\n                    \"id\": \"738964000000291009\"\n                }\n            },\n            \"message\": \"tags merged successfully\",\n            \"status\": \"success\"\n        }\n    ]\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"tags\": [\n       {\n            \"conflict_id\": \"{{id of the tag which you want to merge}}\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/tags/738964000002130339/actions/merg",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "tags",
            "738964000002130339",
            "actions",
            "merg"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:48:26 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "131"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Frame-Options",
          "value": "deny"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_URL_PATTERN\",\n    \"details\": {},\n    \"message\": \"Please check if the URL trying to access is a correct one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_REQUEST_METHOD",
      "originalRequest": {
        "method": "COPY",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"tags\": [\n       {\n            \"conflict_id\": \"{{id of the tag which you want to merge}}\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/tags/738964000002130339/actions/merge",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "tags",
            "738964000002130339",
            "actions",
            "merge"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:48:46 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "124"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Frame-Options",
          "value": "deny"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_REQUEST_METHOD\",\n    \"details\": {},\n    \"message\": \"The http request method type is not a valid one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "UNABLE_TO_PARSE_DATA_TYPE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"tags\": [\n       {\n            \"conflict_id\": \"{{id of the tag which you want to merge}}\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/tags/738964000002130339/actions/merge",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "tags",
            "738964000002130339",
            "actions",
            "merge"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:49:02 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\": \"UNABLE_TO_PARSE_DATA_TYPE\",\n    \"details\": {},\n    \"message\": \"either the request body or parameters is in wrong format\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "AUTHENTICATION_FAILURE",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"tags\": [\n       {\n            \"conflict_id\": \"738964000002130340\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/tags/738964000002130339/actions/merge",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "tags",
            "738964000002130339",
            "actions",
            "merge"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:50:02 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "98"
        },
        {
          "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\": \"AUTHENTICATION_FAILURE\",\n    \"details\": {},\n    \"message\": \"Authentication failed\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "MANDATORY_NOT_FOUND",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"tags\": [\n       {\n           \n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/settings/tags/738964000002130339/actions/merge",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "settings",
            "tags",
            "738964000002130339",
            "actions",
            "merge"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 06:50:21 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "132"
        },
        {
          "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-store, no-cache, must-revalidate, private"
        },
        {
          "key": "Expires",
          "value": "Thu, 01 Jan 1970 00:00:00 GMT"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-ACCESSTOKEN-RESET",
          "value": "2021-05-12T07:15:06+00:00"
        },
        {
          "key": "clientVersion",
          "value": "4027076"
        },
        {
          "key": "clientsubVersion",
          "value": "748ecbe82ec7e144b66ee25f264bbd88"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=15768000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"tags\": [\n        {\n            \"code\": \"MANDATORY_NOT_FOUND\",\n            \"details\": {\n                \"api_name\": \"conflict_id\"\n            },\n            \"message\": \"required field not found\",\n            \"status\": \"error\"\n        }\n    ]\n}"
    }
  ]
}