Perl / Support API / Listing Comments
Back to Collection Items
use chilkat();
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$http = chilkat::CkHttp->new();
$http->put_BasicAuth(1);
$http->put_Login("login");
$http->put_Password("password");
$queryParams = chilkat::CkJsonObject->new();
$queryParams->UpdateString("since","<string>");
$queryParams->UpdateString("role","<string>");
$http->SetRequestHeader("Accept","application/json");
# resp is a HttpResponse
$resp = $http->QuickRequestParams("GET","https://example.zendesk.com/api/v2/requests/:request_id/comments",$queryParams);
if ($http->get_LastMethodSuccess() == 0) {
print $http->lastErrorText() . "\r\n";
exit;
}
$sbResponseBody = chilkat::CkStringBuilder->new();
$resp->GetBodySb($sbResponseBody);
$jResp = chilkat::CkJsonObject->new();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(0);
print "Response Body:" . "\r\n";
print $jResp->emit() . "\r\n";
$respStatusCode = $resp->get_StatusCode();
print "Response Status Code = " . $respStatusCode . "\r\n";
if ($respStatusCode >= 400) {
print "Response Header:" . "\r\n";
print $resp->header() . "\r\n";
print "Failed." . "\r\n";
exit;
}
# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)
# {
# "comments": [
# {
# "attachments": [
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>",
# "thumbnails": [
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# },
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# }
# ]
# },
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>",
# "thumbnails": [
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# },
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# }
# ]
# }
# ],
# "audit_id": "<integer>",
# "author_id": "<integer>",
# "body": "<string>",
# "created_at": "<dateTime>",
# "html_body": "<string>",
# "id": "<integer>",
# "metadata": {
# "cillum_7ae": "laboris nulla fugiat",
# "sunt2": 25522168.26328881,
# "laboris__": true
# },
# "plain_body": "<string>",
# "public": "<boolean>",
# "type": "<string>",
# "uploads": [
# "<string>",
# "<string>"
# ],
# "via": {
# "channel": "<string>",
# "source": {
# "incididunt03e": false,
# "eiusmod_4": -36679297,
# "esse7": 87176441
# }
# }
# },
# {
# "attachments": [
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>",
# "thumbnails": [
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# },
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# }
# ]
# },
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>",
# "thumbnails": [
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# },
# {
# "content_type": "<string>",
# "content_url": "<string>",
# "deleted": "<boolean>",
# "file_name": "<string>",
# "height": "<string>",
# "id": "<integer>",
# "inline": "<boolean>",
# "malware_access_override": "<boolean>",
# "malware_scan_result": "<string>",
# "mapped_content_url": "<string>",
# "size": "<integer>",
# "url": "<string>",
# "width": "<string>"
# }
# ]
# }
# ],
# "audit_id": "<integer>",
# "author_id": "<integer>",
# "body": "<string>",
# "created_at": "<dateTime>",
# "html_body": "<string>",
# "id": "<integer>",
# "metadata": {
# "nisi04": false
# },
# "plain_body": "<string>",
# "public": "<boolean>",
# "type": "<string>",
# "uploads": [
# "<string>",
# "<string>"
# ],
# "via": {
# "channel": "<string>",
# "source": {
# "amet__": 87553399
# }
# }
# }
# ]
# }
# 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("comments");
while ($i < $count_i) {
$jResp->put_I($i);
$audit_id = $jResp->stringOf("comments[i].audit_id");
$author_id = $jResp->stringOf("comments[i].author_id");
$body = $jResp->stringOf("comments[i].body");
$created_at = $jResp->stringOf("comments[i].created_at");
$html_body = $jResp->stringOf("comments[i].html_body");
$id = $jResp->stringOf("comments[i].id");
$Cillum_7ae = $jResp->stringOf("comments[i].metadata.cillum_7ae");
$Sunt2 = $jResp->stringOf("comments[i].metadata.sunt2");
$Laboris__ = $jResp->BoolOf("comments[i].metadata.laboris__");
$plain_body = $jResp->stringOf("comments[i].plain_body");
$v_public = $jResp->stringOf("comments[i].public");
$v_type = $jResp->stringOf("comments[i].type");
$Channel = $jResp->stringOf("comments[i].via.channel");
$Incididunt03e = $jResp->BoolOf("comments[i].via.source.incididunt03e");
$Eiusmod_4 = $jResp->IntOf("comments[i].via.source.eiusmod_4");
$Esse7 = $jResp->IntOf("comments[i].via.source.esse7");
$Nisi04 = $jResp->BoolOf("comments[i].metadata.nisi04");
$Amet__ = $jResp->IntOf("comments[i].via.source.amet__");
$j = 0;
$count_j = $jResp->SizeOfArray("comments[i].attachments");
while ($j < $count_j) {
$jResp->put_J($j);
$content_type = $jResp->stringOf("comments[i].attachments[j].content_type");
$content_url = $jResp->stringOf("comments[i].attachments[j].content_url");
$deleted = $jResp->stringOf("comments[i].attachments[j].deleted");
$file_name = $jResp->stringOf("comments[i].attachments[j].file_name");
$height = $jResp->stringOf("comments[i].attachments[j].height");
$id = $jResp->stringOf("comments[i].attachments[j].id");
$inline = $jResp->stringOf("comments[i].attachments[j].inline");
$malware_access_override = $jResp->stringOf("comments[i].attachments[j].malware_access_override");
$malware_scan_result = $jResp->stringOf("comments[i].attachments[j].malware_scan_result");
$mapped_content_url = $jResp->stringOf("comments[i].attachments[j].mapped_content_url");
$size = $jResp->stringOf("comments[i].attachments[j].size");
$url = $jResp->stringOf("comments[i].attachments[j].url");
$width = $jResp->stringOf("comments[i].attachments[j].width");
$k = 0;
$count_k = $jResp->SizeOfArray("comments[i].attachments[j].thumbnails");
while ($k < $count_k) {
$jResp->put_K($k);
$content_type = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].content_type");
$content_url = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].content_url");
$deleted = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].deleted");
$file_name = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].file_name");
$height = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].height");
$id = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].id");
$inline = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].inline");
$malware_access_override = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].malware_access_override");
$malware_scan_result = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].malware_scan_result");
$mapped_content_url = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].mapped_content_url");
$size = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].size");
$url = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].url");
$width = $jResp->stringOf("comments[i].attachments[j].thumbnails[k].width");
$k = $k + 1;
}
$j = $j + 1;
}
$j = 0;
$count_j = $jResp->SizeOfArray("comments[i].uploads");
while ($j < $count_j) {
$jResp->put_J($j);
$strVal = $jResp->stringOf("comments[i].uploads[j]");
$j = $j + 1;
}
$i = $i + 1;
}
Curl Command
curl -u login:password -G -d "since=%3Cstring%3E"
-d "role=%3Cstring%3E"
-H "Accept: application/json"
https://example.zendesk.com/api/v2/requests/:request_id/comments
Postman Collection Item JSON
{
"name": "Listing Comments",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/requests/:request_id/comments?since=<string>&role=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"requests",
":request_id",
"comments"
],
"query": [
{
"key": "since",
"value": "<string>",
"description": "Filters the comments from the given datetime"
},
{
"key": "role",
"value": "<string>",
"description": "One of \"agent\", \"end_user\". If not specified it does not filter"
}
],
"variable": [
{
"key": "request_id",
"value": "<integer>"
}
]
},
"description": "#### Pagination\n\n- Cursor pagination (recommended)\n- Offset pagination\n\nSee [Pagination](/api-reference/introduction/pagination/).\n\n#### Sorting\n\nBy default, comments are sorted by creation date in ascending order.\n\nWhen using cursor pagination, use the following parameter to change the sort order:\n\n| Name | Type | Required | Comments\n| ------ | ------ | -------- | --------\n| `sort` | string | no | Possible values are \"created_at\" (ascending order) or \"-created_at\" (descending order)\n\nWhen using offset pagination, use the following parameters to change the sort order:\n\n| Name | Type | Required | Comments\n| ------------ | ------ | -------- | --------\n| `sort_by` | string | no | One of `created_at`, `updated_at`\n| `sort_order` | string | no | One of `asc`, `desc`\n\n#### Allowed For\n\n* End Users\n"
},
"response": [
{
"name": "Success response",
"originalRequest": {
"method": "GET",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/requests/:request_id/comments?since=<string>&role=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"requests",
":request_id",
"comments"
],
"query": [
{
"key": "since",
"value": "<string>",
"description": "Filters the comments from the given datetime"
},
{
"key": "role",
"value": "<string>",
"description": "One of \"agent\", \"end_user\". If not specified it does not filter"
}
],
"variable": [
{
"key": "request_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"comments\": [\n {\n \"attachments\": [\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\",\n \"thumbnails\": [\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n },\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n }\n ]\n },\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\",\n \"thumbnails\": [\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n },\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n }\n ]\n }\n ],\n \"audit_id\": \"<integer>\",\n \"author_id\": \"<integer>\",\n \"body\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"html_body\": \"<string>\",\n \"id\": \"<integer>\",\n \"metadata\": {\n \"cillum_7ae\": \"laboris nulla fugiat\",\n \"sunt2\": 25522168.26328881,\n \"laboris__\": true\n },\n \"plain_body\": \"<string>\",\n \"public\": \"<boolean>\",\n \"type\": \"<string>\",\n \"uploads\": [\n \"<string>\",\n \"<string>\"\n ],\n \"via\": {\n \"channel\": \"<string>\",\n \"source\": {\n \"incididunt03e\": false,\n \"eiusmod_4\": -36679297,\n \"esse7\": 87176441\n }\n }\n },\n {\n \"attachments\": [\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\",\n \"thumbnails\": [\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n },\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n }\n ]\n },\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\",\n \"thumbnails\": [\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n },\n {\n \"content_type\": \"<string>\",\n \"content_url\": \"<string>\",\n \"deleted\": \"<boolean>\",\n \"file_name\": \"<string>\",\n \"height\": \"<string>\",\n \"id\": \"<integer>\",\n \"inline\": \"<boolean>\",\n \"malware_access_override\": \"<boolean>\",\n \"malware_scan_result\": \"<string>\",\n \"mapped_content_url\": \"<string>\",\n \"size\": \"<integer>\",\n \"url\": \"<string>\",\n \"width\": \"<string>\"\n }\n ]\n }\n ],\n \"audit_id\": \"<integer>\",\n \"author_id\": \"<integer>\",\n \"body\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"html_body\": \"<string>\",\n \"id\": \"<integer>\",\n \"metadata\": {\n \"nisi04\": false\n },\n \"plain_body\": \"<string>\",\n \"public\": \"<boolean>\",\n \"type\": \"<string>\",\n \"uploads\": [\n \"<string>\",\n \"<string>\"\n ],\n \"via\": {\n \"channel\": \"<string>\",\n \"source\": {\n \"amet__\": 87553399\n }\n }\n }\n ]\n}"
}
]
}