Chilkat Online Tools

VB.NET / Zoho CRM REST APIs / Products

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

' 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"
'     }
'   ]
' }

Dim json As New Chilkat.JsonObject
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.AuthToken = "<access_token>"

Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)

Dim resp As Chilkat.HttpResponse = http.PTextSb("PUT","https://domain.com/crm/v2/Products/{{record_id}}/actions/share",sbRequestBody,"utf-8","application/json",False,False)
If (http.LastMethodSuccess = False) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Dim sbResponseBody As New Chilkat.StringBuilder
resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

Debug.WriteLine("Response Body:")
Debug.WriteLine(jResp.Emit())

Dim respStatusCode As Integer = resp.StatusCode
Debug.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(resp.Header)
    Debug.WriteLine("Failed.")

    Exit Sub
End If



' 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



Dim code As String
Dim message As String
Dim status As String

Dim i As Integer = 0
Dim count_i As Integer = jResp.SizeOfArray("share")
While i < count_i
    jResp.I = i
    code = jResp.StringOf("share[i].code")
    message = jResp.StringOf("share[i].message")
    status = jResp.StringOf("share[i].status")
    i = i + 1
End While

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}"
    }
  ]
}