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'
var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jsonResponse: HCkJsonObject;
id: PWideChar;
key: PWideChar;
self: PWideChar;
begin
rest := CkRest_Create();
// URL: https://your-domain.atlassian.net/rest/api/2/issue
bTls := True;
port := 443;
bAutoReconnect := True;
success := CkRest_Connect(rest,'your-domain.atlassian.net',port,bTls,bAutoReconnect);
if (success <> True) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
CkRest_SetAuthBasic(rest,'jira@example.com','JIRA_API_TOKEN');
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'fields.project.id','10000');
CkJsonObject_UpdateString(json,'fields.summary','something is wrong');
CkJsonObject_UpdateString(json,'fields.issuetype.id','10000');
CkJsonObject_UpdateString(json,'fields.assignee.name','matt');
CkJsonObject_UpdateString(json,'fields.priority.id','3');
CkJsonObject_UpdateString(json,'fields.labels[0]','bugfix');
CkJsonObject_UpdateString(json,'fields.labels[1]','blitz_test');
CkJsonObject_UpdateString(json,'fields.description','description');
CkJsonObject_UpdateString(json,'fields.fixVersions[0].id','10001');
CkJsonObject_UpdateString(json,'fields.customfield_10005','blah blah');
CkRest_AddHeader(rest,'Content-Type','application/json');
CkRest_AddHeader(rest,'Accept','application/json');
sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/rest/api/2/issue',sbRequestBody,sbResponseBody);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
respStatusCode := CkRest_getResponseStatusCode(rest);
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkRest__responseHeader(rest));
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
Exit;
end;
jsonResponse := CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);
id := CkJsonObject__stringOf(jsonResponse,'id');
key := CkJsonObject__stringOf(jsonResponse,'key');
self := CkJsonObject__stringOf(jsonResponse,'self');
CkRest_Dispose(rest);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);
{
"id": "10023",
"key": "SCRUM-24",
"self": "https://chilkat.atlassian.net/rest/api/2/issue/10023"
}