Chilkat Online Tools

Python / Zoho CRM REST APIs / Products

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.

# {
#   "share": [
#     {
#       "user": {
#         "id": "{{user_id}}"
#       },
#       "share_related_records": true,
#       "permission": "read_only"
#     },
#     {
#       "user": {
#         "id": "{{user_id}}"
#       },
#       "share_related_records": false,
#       "permission": "full_access"
#     }
#   ]
# }

json = chilkat.CkJsonObject()
json.UpdateString("share[0].user.id","{{user_id}}")
json.UpdateBool("share[0].share_related_records",True)
json.UpdateString("share[0].permission","read_only")
json.UpdateString("share[1].user.id","{{user_id}}")
json.UpdateBool("share[1].share_related_records",False)
json.UpdateString("share[1].permission","full_access")

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

sbRequestBody = chilkat.CkStringBuilder()
json.EmitSb(sbRequestBody)

# resp is a CkHttpResponse
resp = http.PTextSb("PUT","https://domain.com/crm/v2/Products/{{record_id}}/actions/share",sbRequestBody,"utf-8","application/json",False,False)
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)

# {
#   "share": [
#     {
#       "code": "SUCCESS",
#       "details": {},
#       "message": "record will be shared successfully",
#       "status": "success"
#     },
#     {
#       "code": "SUCCESS",
#       "details": {},
#       "message": "record will be shared 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("share")
while i < count_i :
    jResp.put_I(i)
    code = jResp.stringOf("share[i].code")
    message = jResp.stringOf("share[i].message")
    status = jResp.stringOf("share[i].status")
    i = i + 1

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
    "share": [
        {
            "user": {
                "id": "{{user_id}}"
            },
            "share_related_records": true,
            "permission": "read_only"
        },
        {
            "user": {
                "id": "{{user_id}}"
            },
            "share_related_records": false,
            "permission": "full_access"
        }
    ]
}'
https://domain.com/crm/v2/Products/{{record_id}}/actions/share

Postman Collection Item JSON

{
  "name": "Products",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"{{user_id}}\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"{{user_id}}\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{api-domain}}/crm/v2/Products/{{record_id}}/actions/share",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2",
        "Products",
        "{{record_id}}",
        "actions",
        "share"
      ]
    },
    "description": "Update the sharing permissions of the shared record."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"4150868000001199001\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"4150868000001248015\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Products/4150868000003278032/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Products",
            "4150868000003278032",
            "actions",
            "share"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:59:23 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "207"
        },
        {
          "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-13T12:00:55+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4027494"
        },
        {
          "key": "clientsubVersion",
          "value": "431c911d4bfb6433a6ca32fc6f70a7a3"
        },
        {
          "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    \"share\": [\n        {\n            \"code\": \"SUCCESS\",\n            \"details\": {},\n            \"message\": \"record will be shared successfully\",\n            \"status\": \"success\"\n        },\n        {\n            \"code\": \"SUCCESS\",\n            \"details\": {},\n            \"message\": \"record will be shared successfully\",\n            \"status\": \"success\"\n        }\n    ]\n}"
    },
    {
      "name": "INVALID_MODULE",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"4150868000001199001\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"4150868000001248015\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Product/4150868000003278032/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Product",
            "4150868000003278032",
            "actions",
            "share"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 05:59:56 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "110"
        },
        {
          "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-13T12:00:55+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4027494"
        },
        {
          "key": "clientsubVersion",
          "value": "431c911d4bfb6433a6ca32fc6f70a7a3"
        },
        {
          "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_MODULE\",\n    \"details\": {},\n    \"message\": \"the module name given seems to be invalid\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_URL_PATTERN",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"4150868000001199001\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"4150868000001248015\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Products/4150868000003278032/action/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Products",
            "4150868000003278032",
            "action",
            "share"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 06:00:09 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "131"
        },
        {
          "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-13T12:00:55+05:30"
        },
        {
          "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_URL_PATTERN\",\n    \"details\": {},\n    \"message\": \"Please check if the URL trying to access is a correct one\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_DATA",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"4150868000001199001\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"4150868000001248015\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Products/415086800000327803/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Products",
            "415086800000327803",
            "actions",
            "share"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 06:00:29 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "115"
        },
        {
          "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-13T12:00:55+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4027494"
        },
        {
          "key": "clientsubVersion",
          "value": "431c911d4bfb6433a6ca32fc6f70a7a3"
        },
        {
          "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        \"entityId\": \"415086800000327803\"\n    },\n    \"message\": \"ENTITY_ID_INVALID\",\n    \"status\": \"error\"\n}"
    },
    {
      "name": "INVALID_REQUEST_METHOD",
      "originalRequest": {
        "method": "COPY",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"4150868000001199001\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"4150868000001248015\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Products/415086800000327803/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Products",
            "415086800000327803",
            "actions",
            "share"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 06:00:44 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": "AUTHENTICATION_FAILURE",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"4150868000001199001\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"4150868000001248015\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Products/415086800000327803/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Products",
            "415086800000327803",
            "actions",
            "share"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 06:01:03 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": "INVALID_REQUEST",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"share\": [\n        {\n            \"user\": {\n                \"id\": \"{{user_id}}\"\n            },\n            \"share_related_records\": true,\n            \"permission\": \"read_only\"\n        },\n        {\n            \"user\": {\n                \"id\": \"{{user_id}}\"\n            },\n            \"share_related_records\": false,\n            \"permission\": \"full_access\"\n        }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{api-domain}}/crm/v2/Products/{{record_id}}/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Products",
            "{{record_id}}",
            "actions",
            "share"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 06:44:21 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-Download-Options",
          "value": "noopen"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"code\": \"INVALID_REQUEST\",\n    \"details\": {},\n    \"message\": \"unable to process your request. please verify whether you have entered proper method name, parameter and parameter values.\",\n    \"status\": \"error\"\n}"
    }
  ]
}