C / Support API / Search Custom Object Records
Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject queryParams;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *name;
const char *created_at;
const char *created_by_user_id;
const char *Voluptate571;
const char *Aute_e;
const char *Nostrud_6f;
const char *custom_object_key;
const char *external_id;
const char *id;
const char *updated_at;
const char *updated_by_user_id;
const char *url;
const char *Eu4;
const char *count;
const char *next_page;
const char *previous_page;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
CkHttp_putBasicAuth(http,TRUE);
CkHttp_putLogin(http,"login");
CkHttp_putPassword(http,"password");
queryParams = CkJsonObject_Create();
CkJsonObject_UpdateString(queryParams,"name","<string>");
CkHttp_SetRequestHeader(http,"Accept","application/json");
resp = CkHttp_QuickRequestParams(http,"GET","https://example.zendesk.com/api/v2/custom_objects/:custom_object_key/records/autocomplete",queryParams);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "count": "<integer>",
// "custom_object_records": [
// {
// "name": "<string>",
// "created_at": "<dateTime>",
// "created_by_user_id": "<string>",
// "custom_object_fields": {
// "voluptate571": "<string>",
// "aute_e": "<string>",
// "nostrud_6f": "<string>"
// },
// "custom_object_key": "<string>",
// "external_id": "<string>",
// "id": "<string>",
// "updated_at": "<dateTime>",
// "updated_by_user_id": "<string>",
// "url": "<string>"
// },
// {
// "name": "<string>",
// "created_at": "<dateTime>",
// "created_by_user_id": "<string>",
// "custom_object_fields": {
// "eu4": "<string>"
// },
// "custom_object_key": "<string>",
// "external_id": "<string>",
// "id": "<string>",
// "updated_at": "<dateTime>",
// "updated_by_user_id": "<string>",
// "url": "<string>"
// }
// ],
// "next_page": "<string>",
// "previous_page": "<string>"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
count = CkJsonObject_stringOf(jResp,"count");
next_page = CkJsonObject_stringOf(jResp,"next_page");
previous_page = CkJsonObject_stringOf(jResp,"previous_page");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"custom_object_records");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
name = CkJsonObject_stringOf(jResp,"custom_object_records[i].name");
created_at = CkJsonObject_stringOf(jResp,"custom_object_records[i].created_at");
created_by_user_id = CkJsonObject_stringOf(jResp,"custom_object_records[i].created_by_user_id");
Voluptate571 = CkJsonObject_stringOf(jResp,"custom_object_records[i].custom_object_fields.voluptate571");
Aute_e = CkJsonObject_stringOf(jResp,"custom_object_records[i].custom_object_fields.aute_e");
Nostrud_6f = CkJsonObject_stringOf(jResp,"custom_object_records[i].custom_object_fields.nostrud_6f");
custom_object_key = CkJsonObject_stringOf(jResp,"custom_object_records[i].custom_object_key");
external_id = CkJsonObject_stringOf(jResp,"custom_object_records[i].external_id");
id = CkJsonObject_stringOf(jResp,"custom_object_records[i].id");
updated_at = CkJsonObject_stringOf(jResp,"custom_object_records[i].updated_at");
updated_by_user_id = CkJsonObject_stringOf(jResp,"custom_object_records[i].updated_by_user_id");
url = CkJsonObject_stringOf(jResp,"custom_object_records[i].url");
Eu4 = CkJsonObject_stringOf(jResp,"custom_object_records[i].custom_object_fields.eu4");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -u login:password -G -d "name=%3Cstring%3E"
-H "Accept: application/json"
https://example.zendesk.com/api/v2/custom_objects/:custom_object_key/records/autocomplete
Postman Collection Item JSON
{
"name": "Search Custom Object Records",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/custom_objects/:custom_object_key/records/autocomplete?name=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_objects",
":custom_object_key",
"records",
"autocomplete"
],
"query": [
{
"key": "name",
"value": "<string>",
"description": "Part of a name of the record you are searching for"
}
],
"variable": [
{
"key": "custom_object_key",
"value": "<string>"
}
]
},
"description": "Search for a record by its name\n#### Allowed For\n* Everyone"
},
"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/custom_objects/:custom_object_key/records/autocomplete?name=<string>",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"custom_objects",
":custom_object_key",
"records",
"autocomplete"
],
"query": [
{
"key": "name",
"value": "<string>",
"description": "Part of a name of the record you are searching for"
}
],
"variable": [
{
"key": "custom_object_key"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"count\": \"<integer>\",\n \"custom_object_records\": [\n {\n \"name\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"created_by_user_id\": \"<string>\",\n \"custom_object_fields\": {\n \"voluptate571\": \"<string>\",\n \"aute_e\": \"<string>\",\n \"nostrud_6f\": \"<string>\"\n },\n \"custom_object_key\": \"<string>\",\n \"external_id\": \"<string>\",\n \"id\": \"<string>\",\n \"updated_at\": \"<dateTime>\",\n \"updated_by_user_id\": \"<string>\",\n \"url\": \"<string>\"\n },\n {\n \"name\": \"<string>\",\n \"created_at\": \"<dateTime>\",\n \"created_by_user_id\": \"<string>\",\n \"custom_object_fields\": {\n \"eu4\": \"<string>\"\n },\n \"custom_object_key\": \"<string>\",\n \"external_id\": \"<string>\",\n \"id\": \"<string>\",\n \"updated_at\": \"<dateTime>\",\n \"updated_by_user_id\": \"<string>\",\n \"url\": \"<string>\"\n }\n ],\n \"next_page\": \"<string>\",\n \"previous_page\": \"<string>\"\n}"
}
]
}