Chilkat Online Tools

C# / Zoho CRM REST APIs / Leads

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;

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>";

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
success = http.QuickGetSb("https://domain.com/crm/v2/Leads/{{record_id}}/Attachments",sbResponseBody);
if (success == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

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

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

int respStatusCode = http.LastStatus;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(http.LastHeader);
    Debug.WriteLine("Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": [
//     {
//       "Owner": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "Modified_Time": "2021-05-03T17:59:02+05:30",
//       "File_Name": "0f2b4454e6fea3b4c8fcc82e7d2601b0.jpg",
//       "Created_Time": "2021-05-03T17:59:02+05:30",
//       "Size": "563181",
//       "Parent_Id": {
//         "name": "Brian Dolan",
//         "id": "4150868000004943003"
//       },
//       "$editable": true,
//       "$file_id": "1nvs60c82c750d8564edeaf5093ecadff1c9a",
//       "$type": "Attachment",
//       "$se_module": "Leads",
//       "Modified_By": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "$state": "save",
//       "id": "4150868000005282007",
//       "Created_By": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "$link_url": null
//     },
//     {
//       "Owner": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "Modified_Time": "2021-05-03T18:05:58+05:30",
//       "File_Name": "4150868000001144115.zip",
//       "Created_Time": "2021-05-03T18:05:58+05:30",
//       "Size": "335",
//       "Parent_Id": {
//         "name": "Brian Dolan",
//         "id": "4150868000004943003"
//       },
//       "$editable": true,
//       "$file_id": "1nvs652667149a3684a938b5e751e55a280f5",
//       "$type": "Attachment",
//       "$se_module": "Leads",
//       "Modified_By": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "$state": "save",
//       "id": "4150868000005277042",
//       "Created_By": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "$link_url": null
//     },
//     {
//       "Owner": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "Modified_Time": "2021-05-03T18:03:00+05:30",
//       "File_Name": "0f2b4454e6fea3b4c8fcc82e7d2601b0.jpg",
//       "Created_Time": "2021-05-03T18:03:00+05:30",
//       "Size": "563181",
//       "Parent_Id": {
//         "name": "Brian Dolan",
//         "id": "4150868000004943003"
//       },
//       "$editable": true,
//       "$file_id": "1nvs632039a760ec04736b291c070a4a60b11",
//       "$type": "Attachment",
//       "$se_module": "Leads",
//       "Modified_By": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "$state": "save",
//       "id": "4150868000005277036",
//       "Created_By": {
//         "name": "Patricia Boyle",
//         "id": "4150868000000225013",
//         "email": "patricia.ss@zylker.com"
//       },
//       "$link_url": null
//     }
//   ],
//   "info": {
//     "per_page": 200,
//     "count": 3,
//     "page": 1,
//     "more_records": false
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

string Name;
string Id;
string v_Email;
string Modified_Time;
string File_Name;
string Created_Time;
string Size;
string Parent_IdName;
string Parent_IdId;
bool Seditable;
string Sfile_id;
string Stype;
string Sse_module;
string Modified_ByName;
string Modified_ById;
string Modified_ByEmail;
string Sstate;
string id;
string Created_ByName;
string Created_ById;
string Created_ByEmail;
string Slink_url;

int Per_page = jResp.IntOf("info.per_page");
int Count = jResp.IntOf("info.count");
int Page = jResp.IntOf("info.page");
bool More_records = jResp.BoolOf("info.more_records");
int i = 0;
int count_i = jResp.SizeOfArray("data");
while (i < count_i) {
    jResp.I = i;
    Name = jResp.StringOf("data[i].Owner.name");
    Id = jResp.StringOf("data[i].Owner.id");
    v_Email = jResp.StringOf("data[i].Owner.email");
    Modified_Time = jResp.StringOf("data[i].Modified_Time");
    File_Name = jResp.StringOf("data[i].File_Name");
    Created_Time = jResp.StringOf("data[i].Created_Time");
    Size = jResp.StringOf("data[i].Size");
    Parent_IdName = jResp.StringOf("data[i].Parent_Id.name");
    Parent_IdId = jResp.StringOf("data[i].Parent_Id.id");
    Seditable = jResp.BoolOf("data[i].$editable");
    Sfile_id = jResp.StringOf("data[i].$file_id");
    Stype = jResp.StringOf("data[i].$type");
    Sse_module = jResp.StringOf("data[i].$se_module");
    Modified_ByName = jResp.StringOf("data[i].Modified_By.name");
    Modified_ById = jResp.StringOf("data[i].Modified_By.id");
    Modified_ByEmail = jResp.StringOf("data[i].Modified_By.email");
    Sstate = jResp.StringOf("data[i].$state");
    id = jResp.StringOf("data[i].id");
    Created_ByName = jResp.StringOf("data[i].Created_By.name");
    Created_ById = jResp.StringOf("data[i].Created_By.id");
    Created_ByEmail = jResp.StringOf("data[i].Created_By.email");
    Slink_url = jResp.StringOf("data[i].$link_url");
    i = i + 1;
}

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/crm/v2/Leads/{{record_id}}/Attachments

Postman Collection Item JSON

{
  "name": "Leads",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{access-token}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{api-domain}}/crm/v2/Leads/{{record_id}}/Attachments",
      "host": [
        "{{api-domain}}"
      ],
      "path": [
        "crm",
        "v2",
        "Leads",
        "{{record_id}}",
        "Attachments"
      ]
    },
    "description": "To get the list of attachments."
  },
  "response": [
    {
      "name": "SUCCESS RESPONSE",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/4150868000004943003/Attachments",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "4150868000004943003",
            "Attachments"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:16:13 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=utf-8"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "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-12T17:36:34+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4026785"
        },
        {
          "key": "clientsubVersion",
          "value": "0881d46feece8d60fdd69acfa4e7918b"
        },
        {
          "key": "Content-Disposition",
          "value": "attachment; filename=response.json"
        },
        {
          "key": "vary",
          "value": "accept-encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Content-Language",
          "value": "en-US"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": [\n        {\n            \"Owner\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"Modified_Time\": \"2021-05-03T17:59:02+05:30\",\n            \"File_Name\": \"0f2b4454e6fea3b4c8fcc82e7d2601b0.jpg\",\n            \"Created_Time\": \"2021-05-03T17:59:02+05:30\",\n            \"Size\": \"563181\",\n            \"Parent_Id\": {\n                \"name\": \"Brian Dolan\",\n                \"id\": \"4150868000004943003\"\n            },\n            \"$editable\": true,\n            \"$file_id\": \"1nvs60c82c750d8564edeaf5093ecadff1c9a\",\n            \"$type\": \"Attachment\",\n            \"$se_module\": \"Leads\",\n            \"Modified_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$state\": \"save\",\n            \"id\": \"4150868000005282007\",\n            \"Created_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$link_url\": null\n        },\n        {\n            \"Owner\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"Modified_Time\": \"2021-05-03T18:05:58+05:30\",\n            \"File_Name\": \"4150868000001144115.zip\",\n            \"Created_Time\": \"2021-05-03T18:05:58+05:30\",\n            \"Size\": \"335\",\n            \"Parent_Id\": {\n                \"name\": \"Brian Dolan\",\n                \"id\": \"4150868000004943003\"\n            },\n            \"$editable\": true,\n            \"$file_id\": \"1nvs652667149a3684a938b5e751e55a280f5\",\n            \"$type\": \"Attachment\",\n            \"$se_module\": \"Leads\",\n            \"Modified_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$state\": \"save\",\n            \"id\": \"4150868000005277042\",\n            \"Created_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$link_url\": null\n        },\n        {\n            \"Owner\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"Modified_Time\": \"2021-05-03T18:03:00+05:30\",\n            \"File_Name\": \"0f2b4454e6fea3b4c8fcc82e7d2601b0.jpg\",\n            \"Created_Time\": \"2021-05-03T18:03:00+05:30\",\n            \"Size\": \"563181\",\n            \"Parent_Id\": {\n                \"name\": \"Brian Dolan\",\n                \"id\": \"4150868000004943003\"\n            },\n            \"$editable\": true,\n            \"$file_id\": \"1nvs632039a760ec04736b291c070a4a60b11\",\n            \"$type\": \"Attachment\",\n            \"$se_module\": \"Leads\",\n            \"Modified_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$state\": \"save\",\n            \"id\": \"4150868000005277036\",\n            \"Created_By\": {\n                \"name\": \"Patricia Boyle\",\n                \"id\": \"4150868000000225013\",\n                \"email\": \"patricia.ss@zylker.com\"\n            },\n            \"$link_url\": null\n        }\n    ],\n    \"info\": {\n        \"per_page\": 200,\n        \"count\": 3,\n        \"page\": 1,\n        \"more_records\": false\n    }\n}"
    },
    {
      "name": "INVALID_MODULE",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Lead/4150868000004943003/Attachments",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Lead",
            "4150868000004943003",
            "Attachments"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:16:48 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-12T17:36:34+05:30"
        },
        {
          "key": "clientVersion",
          "value": "4026785"
        },
        {
          "key": "clientsubVersion",
          "value": "0881d46feece8d60fdd69acfa4e7918b"
        },
        {
          "key": "Set-Cookie",
          "value": "JSESSIONID=0F072164DEAA5A20B96AF5BA88F3561E; Path=/; Secure"
        },
        {
          "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_METHOD",
      "originalRequest": {
        "method": "COPY",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/4150868000005335091/Attachments",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "4150868000005335091",
            "Attachments"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:18:40 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": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/4150868000005335091/Attachments",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "4150868000005335091",
            "Attachments"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Wed, 12 May 2021 11:19: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": "OAUTH_SCOPE_MISMATCH",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{api-domain}}/crm/v2/Leads/{{record_id}}/Attachments",
          "host": [
            "{{api-domain}}"
          ],
          "path": [
            "crm",
            "v2",
            "Leads",
            "{{record_id}}",
            "Attachments"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "ZGS"
        },
        {
          "key": "Date",
          "value": "Thu, 13 May 2021 06:40:23 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}"
    }
  ]
}