Creates a new Zendesk ticket with an attachment. The file attachment is indicated by an array of attachment tokens contained within the comment. (The attachment should be uploaded beforehand, and the token can be obtained from the JSON response of the attachment file upload.)
curl -X POST https://subdomain.zendesk.com/api/v2/tickets.json \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"ticket": {
"subject": "My application crashed. Please help.",
"comment": { "body": "Here is a screen shot", "uploads": ["W7Y11FCxfQlzOFPDbVDUEE45C"] }
}
}' \
-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;
const wchar_t *url;
const wchar_t *file_name;
const wchar_t *content_url;
const wchar_t *mapped_content_url;
const wchar_t *content_type;
int size;
const wchar_t *width;
const wchar_t *height;
BOOL inline;
int k;
int count_k;
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 application crashed. Please help.");
CkJsonObjectW_UpdateString(json,L"ticket.comment.body",L"Here is a screen shot");
CkJsonObjectW_UpdateString(json,L"ticket.comment.uploads[0]",L"W7Y11FCxfQlzOFPDbVDUEE45C");
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);
url = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].url");
id = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].attachments[j].id");
file_name = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].file_name");
content_url = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].content_url");
mapped_content_url = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].mapped_content_url");
content_type = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].content_type");
size = CkJsonObjectW_IntOf(jsonResponse,L"audit.events[i].attachments[j].size");
width = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].width");
height = CkJsonObjectW_stringOf(jsonResponse,L"audit.events[i].attachments[j].height");
inline = CkJsonObjectW_BoolOf(jsonResponse,L"audit.events[i].attachments[j].inline");
k = 0;
count_k = CkJsonObjectW_SizeOfArray(jsonResponse,L"audit.events[i].attachments[j].thumbnails");
while (k < count_k) {
CkJsonObjectW_putK(jsonResponse,k);
k = k + 1;
}
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/11.json",
"id": 11,
"external_id": null,
"via": {
"channel": "api",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2018-04-15T20:29:49Z",
"updated_at": "2018-04-15T20:29:49Z",
"type": null,
"subject": "My application crashed. Please help.",
"raw_subject": "My application crashed. Please help.",
"description": "Here is a screen shot",
"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": 391509606014,
"ticket_id": 11,
"created_at": "2018-04-15T20:29:49Z",
"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": 391509606034,
"type": "Comment",
"author_id": 361801727573,
"body": "Here is a screen shot",
"html_body": "<div class=\"zd-comment\"><p dir=\"auto\">Here is a screen shot</p></div>",
"plain_body": "Here is a screen shot",
"public": true,
"attachments": [
{
"url": "https://chilkat.zendesk.com/api/v2/attachments/360887735934.json",
"id": 360887735934,
"file_name": "sample.pdf",
"content_url": "https://chilkat.zendesk.com/attachments/token/Q7wAubpKB2KERnNFj89JmdvS1/?name=sample.pdf",
"mapped_content_url": "https://chilkat.zendesk.com/attachments/token/Q7wAubpKB2KERnNFj89JmdvS1/?name=sample.pdf",
"content_type": "application/pdf",
"size": 178399,
"width": null,
"height": null,
"inline": false,
"thumbnails": [
]
}
],
"audit_id": 391509606014
},
{
"id": 391509606394,
"type": "Create",
"value": "My application crashed. Please help.",
"field_name": "subject"
},
{
"id": 391509606414,
"type": "Create",
"value": "361801727573",
"field_name": "requester_id"
},
{
"id": 391509606434,
"type": "Create",
"value": "open",
"field_name": "status"
},
{
"id": 391509606454,
"type": "Create",
"value": null,
"field_name": "priority"
},
{
"id": 391509606474,
"type": "Create",
"value": null,
"field_name": "type"
},
{
"id": 391509606494,
"type": "Create",
"value": "361801727573",
"field_name": "assignee_id"
},
{
"id": 391509606514,
"type": "Create",
"value": "360000681553",
"field_name": "group_id"
},
{
"id": 391509606534,
"type": "Create",
"value": "360015071793",
"field_name": "organization_id"
},
{
"id": 391509606554,
"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": 391509606574,
"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
}
}
}
}