Creates a new Zendesk ticket.
curl -X POST https://subdomain.zendesk.com/api/v2/tickets.json \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"ticket": {
"subject": "My printer is on fire!",
"comment": {
"body": "The smoke is very colorful."
}
}
}' \
-u zendesk_email:zendesk_password
#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
HCkJsonObjectW jsonResponse;
const wchar_t *ticketUrl;
int ticketId;
const wchar_t *ticketExternal_id;
const wchar_t *ticketViaChannel;
const wchar_t *ticketViaSourceRel;
const wchar_t *ticketCreated_at;
const wchar_t *ticketUpdated_at;
const wchar_t *ticketType;
const wchar_t *ticketSubject;
const wchar_t *ticketRaw_subject;
const wchar_t *ticketDescription;
const wchar_t *ticketPriority;
const wchar_t *ticketStatus;
const wchar_t *ticketRecipient;
int ticketRequester_id;
int ticketSubmitter_id;
int ticketAssignee_id;
int ticketOrganization_id;
int ticketGroup_id;
const wchar_t *ticketForum_topic_id;
const wchar_t *ticketProblem_id;
BOOL ticketHas_incidents;
BOOL ticketIs_public;
const wchar_t *ticketDue_at;
const wchar_t *ticketSatisfaction_rating;
int ticketBrand_id;
BOOL ticketAllow_channelback;
int auditId;
int auditTicket_id;
const wchar_t *auditCreated_at;
int auditAuthor_id;
const wchar_t *auditMetadataSystemIp_address;
const wchar_t *auditMetadataSystemLocation;
int auditMetadataSystemLatitude;
int auditMetadataSystemLongitude;
const wchar_t *auditViaChannel;
const wchar_t *auditViaSourceRel;
int i;
int count_i;
int id;
const wchar_t *type;
int author_id;
const wchar_t *body;
const wchar_t *html_body;
const wchar_t *plain_body;
BOOL public;
int audit_id;
const wchar_t *value;
const wchar_t *field_name;
const wchar_t *viaChannel;
BOOL viaSourceFromDeleted;
const wchar_t *viaSourceFromTitle;
int viaSourceFromId;
const wchar_t *viaSourceRel;
const wchar_t *subject;
int j;
int count_j;
int intVal;
rest = CkRestW_Create();
// URL: https://subdomain.zendesk.com/api/v2/tickets.json
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"subdomain.zendesk.com",port,bTls,bAutoReconnect);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
CkRestW_SetAuthBasic(rest,L"zendesk_email",L"zendesk_password");
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"ticket.subject",L"My printer is on fire!");
CkJsonObjectW_UpdateString(json,L"ticket.comment.body",L"The smoke is very colorful.");
CkRestW_AddHeader(rest,L"Content-Type",L"application/json");
CkRestW_AddHeader(rest,L"Accept",L"application/json");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"POST",L"/api/v2/tickets.json",sbRequestBody,sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jsonResponse = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);
ticketUrl = CkJsonObjectW_stringOf(jsonResponse,L"ticket.url");
ticketId = CkJsonObjectW_IntOf(jsonResponse,L"ticket.id");
ticketExternal_id = CkJsonObjectW_stringOf(jsonResponse,L"ticket.external_id");
ticketViaChannel = CkJsonObjectW_stringOf(jsonResponse,L"ticket.via.channel");
ticketViaSourceRel = CkJsonObjectW_stringOf(jsonResponse,L"ticket.via.source.rel");
ticketCreated_at = CkJsonObjectW_stringOf(jsonResponse,L"ticket.created_at");
ticketUpdated_at = CkJsonObjectW_stringOf(jsonResponse,L"ticket.updated_at");
ticketType = CkJsonObjectW_stringOf(jsonResponse,L"ticket.type");
ticketSubject = CkJsonObjectW_stringOf(jsonResponse,L"ticket.subject");
ticketRaw_subject = CkJsonObjectW_stringOf(jsonResponse,L"ticket.raw_subject");
ticketDescription = CkJsonObjectW_stringOf(jsonResponse,L"ticket.description");
ticketPriority = CkJsonObjectW_stringOf(jsonResponse,L"ticket.priority");
ticketStatus = CkJsonObjectW_stringOf(jsonResponse,L"ticket.status");
ticketRecipient = CkJsonObjectW_stringOf(jsonResponse,L"ticket.recipient");
ticketRequester_id = CkJsonObjectW_IntOf(jsonResponse,L"ticket.requester_id");
ticketSubmitter_id = CkJsonObjectW_IntOf(jsonResponse,L"ticket.submitter_id");
ticketAssignee_id = CkJsonObjectW_IntOf(jsonResponse,L"ticket.assignee_id");
ticketOrganization_id = CkJsonObjectW_IntOf(jsonResponse,L"ticket.organization_id");
ticketGroup_id = CkJsonObjectW_IntOf(jsonResponse,L"ticket.group_id");
ticketForum_topic_id = CkJsonObjectW_stringOf(jsonResponse,L"ticket.forum_topic_id");
ticketProblem_id = CkJsonObjectW_stringOf(jsonResponse,L"ticket.problem_id");
ticketHas_incidents = CkJsonObjectW_BoolOf(jsonResponse,L"ticket.has_incidents");
ticketIs_public = CkJsonObjectW_BoolOf(jsonResponse,L"ticket.is_public");
ticketDue_at = CkJsonObjectW_stringOf(jsonResponse,L"ticket.due_at");
ticketSatisfaction_rating = CkJsonObjectW_stringOf(jsonResponse,L"ticket.satisfaction_rating");
ticketBrand_id = CkJsonObjectW_IntOf(jsonResponse,L"ticket.brand_id");
ticketAllow_channelback = CkJsonObjectW_BoolOf(jsonResponse,L"ticket.allow_channelback");
auditId = CkJsonObjectW_IntOf(jsonResponse,L"audit.id");
auditTicket_id = CkJsonObjectW_IntOf(jsonResponse,L"audit.ticket_id");
auditCreated_at = CkJsonObjectW_stringOf(jsonResponse,L"audit.created_at");
auditAuthor_id = CkJsonObjectW_IntOf(jsonResponse,L"audit.author_id");
auditMetadataSystemIp_address = CkJsonObjectW_stringOf(jsonResponse,L"audit.metadata.system.ip_address");
auditMetadataSystemLocation = CkJsonObjectW_stringOf(jsonResponse,L"audit.metadata.system.location");
auditMetadataSystemLatitude = CkJsonObjectW_IntOf(jsonResponse,L"audit.metadata.system.latitude");
auditMetadataSystemLongitude = CkJsonObjectW_IntOf(jsonResponse,L"audit.metadata.system.longitude");
auditViaChannel = CkJsonObjectW_stringOf(jsonResponse,L"audit.via.channel");
auditViaSourceRel = CkJsonObjectW_stringOf(jsonResponse,L"audit.via.source.rel");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.collaborator_ids");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.follower_ids");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.email_cc_ids");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.tags");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.custom_fields");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.sharing_agreement_ids");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.fields");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"ticket.followup_ids");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"audit.events");
while (i < count_i) {
CkJsonObjectW_putI(jsonResponse,i);
id = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].id");
type = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].type");
author_id = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].author_id");
body = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].body");
html_body = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].html_body");
plain_body = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].plain_body");
public = CkJsonObjectW_BoolOf(jsonResponse,L"audit.events[i].public");
audit_id = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].audit_id");
value = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].value");
field_name = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].field_name");
viaChannel = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].via.channel");
viaSourceFromDeleted = CkJsonObjectW_BoolOf(jsonResponse,L"audit.events[i].via.source.from.deleted");
viaSourceFromTitle = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].via.source.from.title");
viaSourceFromId = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].via.source.from.id");
viaSourceRel = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].via.source.rel");
subject = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].subject");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"audit.events[i].attachments");
while (j < count_j) {
CkJsonObjectW_putJ(jsonResponse,j);
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"audit.events[i].recipients");
while (j < count_j) {
CkJsonObjectW_putJ(jsonResponse,j);
intVal = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].recipients[j]");
j = j + 1;
}
i = i + 1;
}
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jsonResponse);
}
{
"ticket": {
"url": "https://chilkat.zendesk.com/api/v2/tickets/7.json",
"id": 7,
"external_id": null,
"via": {
"channel": "api",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2018-04-15T18:13:15Z",
"updated_at": "2018-04-15T18:13:15Z",
"type": null,
"subject": "My printer is on fire!",
"raw_subject": "My printer is on fire!",
"description": "The smoke is very colorful.",
"priority": null,
"status": "open",
"recipient": null,
"requester_id": 361801727573,
"submitter_id": 361801727573,
"assignee_id": 361801727573,
"organization_id": 360015071793,
"group_id": 360000681553,
"collaborator_ids": [
],
"follower_ids": [
],
"email_cc_ids": [
],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": null,
"tags": [
],
"custom_fields": [
],
"satisfaction_rating": null,
"sharing_agreement_ids": [
],
"fields": [
],
"followup_ids": [
],
"brand_id": 360000471533,
"allow_channelback": false
},
"audit": {
"id": 391248331553,
"ticket_id": 7,
"created_at": "2018-04-15T18:13:15Z",
"author_id": 361801727573,
"metadata": {
"system": {
"ip_address": "52.25.83.238",
"location": "Boardman, OR, United States",
"latitude": 45.86959999999999,
"longitude": -119.688
},
"custom": {}
},
"events": [
{
"id": 391248331653,
"type": "Comment",
"author_id": 361801727573,
"body": "The smoke is very colorful.",
"html_body": "<div class=\"zd-comment\"><p dir=\"auto\">The smoke is very colorful.</p></div>",
"plain_body": "The smoke is very colorful.",
"public": true,
"attachments": [
],
"audit_id": 391248331553
},
{
"id": 391248331833,
"type": "Create",
"value": "My printer is on fire!",
"field_name": "subject"
},
{
"id": 391248331973,
"type": "Create",
"value": "361801727573",
"field_name": "requester_id"
},
{
"id": 391248332053,
"type": "Create",
"value": "open",
"field_name": "status"
},
{
"id": 391248332193,
"type": "Create",
"value": null,
"field_name": "priority"
},
{
"id": 391248332313,
"type": "Create",
"value": null,
"field_name": "type"
},
{
"id": 391248332353,
"type": "Create",
"value": "361801727573",
"field_name": "assignee_id"
},
{
"id": 391248332373,
"type": "Create",
"value": "360000681553",
"field_name": "group_id"
},
{
"id": 391248332393,
"type": "Create",
"value": "360015071793",
"field_name": "organization_id"
},
{
"id": 391248332413,
"type": "Notification",
"via": {
"channel": "rule",
"source": {
"from": {
"deleted": false,
"title": "Notify requester of received request",
"id": 360018516913
},
"rel": "trigger"
}
},
"subject": "[Request received] {{ticket.title}}",
"body": "Your request ({{ticket.id}}) has been received and is being reviewed by our support staff.\n\nTo add additional comments, reply to this email.\n\n{{ticket.comments_formatted}}",
"recipients": [
361801727573
]
},
{
"id": 391248332433,
"type": "Notification",
"via": {
"channel": "rule",
"source": {
"from": {
"deleted": false,
"title": "Notify all agents of received request",
"id": 360018517033
},
"rel": "trigger"
}
},
"subject": "[{{ticket.account}}] {{ticket.title}}",
"body": "A ticket (#{{ticket.id}}) by {{ticket.requester.name}} has been received. It is unassigned.\n\n{{ticket.comments_formatted}}",
"recipients": [
361801727573
]
}
],
"via": {
"channel": "api",
"source": {
"from": {},
"to": {},
"rel": null
}
}
}
}