Creates an issue or a sub-task from a JSON representation.
curl -X POST --user jira@example.com:JIRA_API_TOKEN \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '
{
"fields": {
"project": {
"id": "10000"
},
"summary": "something is wrong",
"issuetype": {
"id": "10000"
},
"assignee": {
"name": "matt"
},
"priority": {
"id": "3"
},
"labels": [
"bugfix",
"blitz_test"
],
"description": "description",
"fixVersions": [
{
"id": "10001"
}
],
"customfield_10005": "blah blah"
}
}' \
--url 'https://your-domain.atlassian.net/rest/api/2/issue'
#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 *id;
const wchar_t *key;
const wchar_t *self;
rest = CkRestW_Create();
// URL: https://your-domain.atlassian.net/rest/api/2/issue
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"your-domain.atlassian.net",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"jira@example.com",L"JIRA_API_TOKEN");
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"fields.project.id",L"10000");
CkJsonObjectW_UpdateString(json,L"fields.summary",L"something is wrong");
CkJsonObjectW_UpdateString(json,L"fields.issuetype.id",L"10000");
CkJsonObjectW_UpdateString(json,L"fields.assignee.name",L"matt");
CkJsonObjectW_UpdateString(json,L"fields.priority.id",L"3");
CkJsonObjectW_UpdateString(json,L"fields.labels[0]",L"bugfix");
CkJsonObjectW_UpdateString(json,L"fields.labels[1]",L"blitz_test");
CkJsonObjectW_UpdateString(json,L"fields.description",L"description");
CkJsonObjectW_UpdateString(json,L"fields.fixVersions[0].id",L"10001");
CkJsonObjectW_UpdateString(json,L"fields.customfield_10005",L"blah blah");
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"/rest/api/2/issue",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);
id = CkJsonObjectW_stringOf(jsonResponse,L"id");
key = CkJsonObjectW_stringOf(jsonResponse,L"key");
self = CkJsonObjectW_stringOf(jsonResponse,L"self");
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jsonResponse);
}
{
"id": "10023",
"key": "SCRUM-24",
"self": "https://chilkat.atlassian.net/rest/api/2/issue/10023"
}