Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// 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"
// }
// ]
// }
let json = CkoJsonObject()!
json.update("share[0].user.id", value: "{{user_id}}")
json.updateBool("share[0].share_related_records", value: true)
json.update("share[0].permission", value: "full_access")
json.update("share[1].user.id", value: "{{user_id}}")
json.updateBool("share[1].share_related_records", value: true)
json.update("share[1].permission", value: "read_only")
// Adds the "Authorization: Bearer <access_token>" header.
http.authToken = "<access_token>"
var resp: CkoHttpResponse? = http.postJson3("https://domain.com/crm/v2.1/Quotes/{{record_id}}/actions/share", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
let sbResponseBody = CkoStringBuilder()!
resp!.getBodySb(sbResponseBody)
let jResp = CkoJsonObject()!
jResp.loadSb(sbResponseBody)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp!.statusCode.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(resp!.header!)")
print("Failed.")
resp = nil
return
}
resp = nil
// 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
var code: String?
var message: String?
var status: String?
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "share").intValue
while i < count_i {
jResp.i = i
code = jResp.string(of: "share[i].code")
message = jResp.string(of: "share[i].message")
status = jResp.string(of: "share[i].status")
i = i + 1
}
}
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.1/Quotes/{{record_id}}/actions/share
Postman Collection Item JSON
{
"name": "Quotes",
"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.1/Quotes/{{record_id}}/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"{{record_id}}",
"actions",
"share"
]
},
"description": "To share a Quote 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.1/Quotes/4150868000004795007/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"actions",
"share"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 10:43:47 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-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 \"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": "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.1/Quotes/4150868000004795007/action/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"4150868000004795007",
"action",
"share"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 10:44:14 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 (record ID)",
"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.1/Quotes/415086800000479500/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"415086800000479500",
"actions",
"share"
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 10:44:40 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-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 \"entityId\": \"415086800000479500\"\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\": \"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.1/Quotes/415086800000479500/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"415086800000479500",
"actions",
"share"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 10:45:06 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\": \"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.1/Quote/415086800000479500/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quote",
"415086800000479500",
"actions",
"share"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Mon, 10 May 2021 10:45:29 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=utf-8"
},
{
"key": "Content-Length",
"value": "133"
},
{
"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_MODULE\",\n \"details\": {\n \"resource_path_index\": 0\n },\n \"message\": \"the module name given seems to be invalid\",\n \"status\": \"error\"\n}"
},
{
"name": "OAUTH_SCOPE_MISMATCH",
"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.1/Quotes/{{record_id}}/actions/share",
"host": [
"{{api-domain}}"
],
"path": [
"crm",
"v2.1",
"Quotes",
"{{record_id}}",
"actions",
"share"
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "ZGS"
},
{
"key": "Date",
"value": "Thu, 13 May 2021 08:18:50 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}"
}
]
}