Objective-C / Support API / Listing Comments
Back to Collection Items
#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <NSString.h>
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;
http.BasicAuth = YES;
http.Login = @"login";
http.Password = @"password";
CkoJsonObject *queryParams = [[CkoJsonObject alloc] init];
[queryParams UpdateString: @"since" value: @"<string>"];
[queryParams UpdateString: @"role" value: @"<string>"];
[http SetRequestHeader: @"Accept" value: @"application/json"];
CkoHttpResponse *resp = [http QuickRequestParams: @"GET" url: @"https://example.zendesk.com/api/v2/requests/:request_id/comments" json: queryParams];
if (http.LastMethodSuccess == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];
CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;
NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);
int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
NSLog(@"%@",@"Response Header:");
NSLog(@"%@",resp.Header);
NSLog(@"%@",@"Failed.");
return;
}
// 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
NSString *audit_id = 0;
NSString *author_id = 0;
NSString *body = 0;
NSString *created_at = 0;
NSString *html_body = 0;
NSString *id = 0;
NSString *Cillum_7ae = 0;
NSString *Sunt2 = 0;
BOOL Laboris__;
NSString *plain_body = 0;
NSString *v_public = 0;
NSString *v_type = 0;
NSString *Channel = 0;
BOOL Incididunt03e;
int Eiusmod_4;
int Esse7;
BOOL Nisi04;
int Amet__;
int j;
int count_j;
NSString *content_type = 0;
NSString *content_url = 0;
NSString *deleted = 0;
NSString *file_name = 0;
NSString *height = 0;
NSString *inline = 0;
NSString *malware_access_override = 0;
NSString *malware_scan_result = 0;
NSString *mapped_content_url = 0;
NSString *size = 0;
NSString *url = 0;
NSString *width = 0;
int k;
int count_k;
NSString *strVal = 0;
int i = 0;
int count_i = [[jResp SizeOfArray: @"comments"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: 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"] intValue];
Esse7 = [[jResp IntOf: @"comments[i].via.source.esse7"] intValue];
Nisi04 = [jResp BoolOf: @"comments[i].metadata.nisi04"];
Amet__ = [[jResp IntOf: @"comments[i].via.source.amet__"] intValue];
j = 0;
count_j = [[jResp SizeOfArray: @"comments[i].attachments"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: 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"] intValue];
while (k < count_k) {
jResp.K = [NSNumber numberWithInt: 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"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: 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}"
}
]
}