Chilkat Online Tools

C# / Zoho CRM REST APIs / Quotes

Back to Collection Items

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

Chilkat.Http http = new Chilkat.Http();
bool success;

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

Chilkat.JsonObject json = 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>";

Chilkat.StringBuilder sbRequestBody = new Chilkat.StringBuilder();
json.EmitSb(sbRequestBody);

Chilkat.HttpResponse resp = http.PTextSb("PUT","https://domain.com/crm/v2.1/Quotes/{{record_id}}/actions/share",sbRequestBody,"utf-8","application/json",false,false);
if (http.LastMethodSuccess == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

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

int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(resp.Header);
    Debug.WriteLine("Failed.");

    return;
}

// 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

string code;
string message;
string status;

int i = 0;
int count_i = 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;
}

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.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": "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.1/Quotes/{{record_id}}/actions/share",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2.1",
        "Quotes",
        "{{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.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:46:24 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_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.1/Quotes/4150868000004795007/action/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "Quotes",
            "4150868000004795007",
            "action",
            "share"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 10:46:49 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-10T17:05:19+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 (record ID)",
      "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.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:47:06 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": "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.1/Quotes/415086800000479500/actions/share",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2.1",
            "Quotes",
            "415086800000479500",
            "actions",
            "share"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Mon, 10 May 2021 10:47:31 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.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:47:49 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": "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.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:48:10 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": "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.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:19:08 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}"
    }
  ]
}