Back to Collection Items
require 'chilkat'
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
http = Chilkat::CkHttp.new()
# 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": "full_access"
# },
# {
# "user": {
# "id": "{{user_id}}"
# },
# "share_related_records": true,
# "permission": "read_only"
# }
# ]
# }
json = Chilkat::CkJsonObject.new()
json.UpdateString("share[0].user.id","{{user_id}}")
json.UpdateBool("share[0].share_related_records",true)
json.UpdateString("share[0].permission","full_access")
json.UpdateString("share[1].user.id","{{user_id}}")
json.UpdateBool("share[1].share_related_records",true)
json.UpdateString("share[1].permission","read_only")
# Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>")
# resp is a CkHttpResponse
resp = http.PostJson3("https://domain.com/crm/v2/Products/{{record_id}}/actions/share","application/json",json)
if (http.get_LastMethodSuccess() == false)
print http.lastErrorText() + "\n";
exit
end
sbResponseBody = Chilkat::CkStringBuilder.new()
resp.GetBodySb(sbResponseBody)
jResp = Chilkat::CkJsonObject.new()
jResp.LoadSb(sbResponseBody)
jResp.put_EmitCompact(false)
print "Response Body:" + "\n";
print jResp.emit() + "\n";
respStatusCode = resp.get_StatusCode()
print "Response Status Code = " + respStatusCode.to_s() + "\n";
if (respStatusCode >= 400)
print "Response Header:" + "\n";
print resp.header() + "\n";
print "Failed." + "\n";
exit
end
# 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
end
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"share": [
{
"user": {
"id": "{{user_id}}"
},
"share_related_records": true,
"permission": "full_access"
},
{
"user": {
"id": "{{user_id}}"
},
"share_related_records": true,
"permission": "read_only"
}
]
}'
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": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\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": "To share a Product with other users in the organization."
},
"response": [
{
"name": "SUCCESS RESPONSE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"4150868000001199001\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"4150868000001248015\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\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:56:52 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_REQUEST_METHOD",
"originalRequest": {
"method": "COPY",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\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 05:57:19 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": "INVALID_DATA",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\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 05:57:55 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": "AUTHENTICATION_FAILURE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\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 05:58:14 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_MODULE",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api-domain}}/crm/v2/Product/415086800000327803/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2",
"Product",
"415086800000327803",
"actions",
"share"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Thu, 13 May 2021 05:58:31 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_REQUEST",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"share\": [\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"full_access\"\n },\n {\n \"user\": {\n \"id\": \"{{user_id}}\"\n },\n \"share_related_records\": true,\n \"permission\": \"read_only\"\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:01 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}"
}
]
}