Ruby Jira - Issues: Delete an Issue

Back to Index

Deletes an issue. This example deletes the issue having key = "SCRUM-13". A successful delete is indicated by a response status code equal to 204 with an empty response body. This example demonstrates one possible JSON error response (where the response status code was 403).

Documentation: https://developers.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-delete

CURL Command

curl -X DELETE --user jira@example.com:JIRA_API_TOKEN \
  --header 'Accept: application/json' \
  --url 'https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-13'

Ruby Example

require 'chilkat'

rest = Chilkat::CkRest.new()

#  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-13
bTls = true
port = 443
bAutoReconnect = true
success = rest.Connect("your-domain.atlassian.net",port,bTls,bAutoReconnect)
if (success != true)
    print "ConnectFailReason: " + rest.get_ConnectFailReason().to_s() + "\n";
    print rest.lastErrorText() + "\n";
    exit
end

rest.SetAuthBasic("jira@example.com","JIRA_API_TOKEN")

rest.AddHeader("Accept","application/json")

sbResponseBody = Chilkat::CkStringBuilder.new()
success = rest.FullRequestNoBodySb("DELETE","/rest/api/2/issue/SCRUM-13",sbResponseBody)
if (success != true)
    print rest.lastErrorText() + "\n";
    exit
end

respStatusCode = rest.get_ResponseStatusCode()
if (respStatusCode >= 400)
    print "Response Status Code = " + respStatusCode.to_s() + "\n";
    print "Response Header:" + "\n";
    print rest.responseHeader() + "\n";
    print "Response Body:" + "\n";
    print sbResponseBody.getAsString() + "\n";
    exit
end

jsonResponse = Chilkat::CkJsonObject.new()
jsonResponse.LoadSb(sbResponseBody)

i = 0
count_i = jsonResponse.SizeOfArray("errorMessages")
while i < count_i
    jsonResponse.put_I(i)
    strVal = jsonResponse.stringOf("errorMessages[i]")
    i = i + 1
end

Sample JSON Response Body

{
  "errorMessages": [
    "You do not have permission to delete issues in this project."
  ],
  "errors": {}
}