Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

DELETE (custom) rest endpoint- ScriptRunner

Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 30, 2018

Hey,
Does anybody have an example of DELETE (custom) rest endpoint for Confluence? (using ScriptRunner plag in)

Thanks

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
JohnsonHoward
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 04, 2018

Hi Neta,

Below is an example of a DELETE REST Endpoint that deletes an issue and returns some Json. If you are experiencing issues when trying to use this with a web item then it will not work. You need to hit this endpoint with a DELETE http request. The options for web items does not include this. 

I have tested this using Postman and it works. You may want to use an AJAX request in a web resource in order to trigger this from an item within your instance.



import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate


deleteIssue(httpMethod: "DELETE"){ MultivaluedMap queryParams ->

def issueId = queryParams.getFirst("issueKey")

IssueManager issueManager = ComponentAccessor.getIssueManager()
IssueService issueService = ComponentAccessor.getComponent(IssueService.class)
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

Issue issue = issueId ? issueManager.getIssueObject(issueId.toString()) : null

def deleteValid = issue ? issueService.validateDelete(currentUser,issue.id) : null
def deleted = deleteValid ? issueService.delete(currentUser,deleteValid,EventDispatchOption.ISSUE_DELETED, false) : null
def errors = deleted?.errors

def flag = []

if(errors){
flag = [
type : 'error',
title: "Error",
close: 'auto',
body : "Something went wrong"
]
}else{

flag = [
type : 'success',
title: "Issue Deleted",
close: 'auto',
body : "Issue Deleted"
]

}
return Response.ok(JsonOutput.toJson(flag)).build()
}

/**
* Created by jhoward on 10/10/2017.
*/

 Thanks

Johnson Howard (Adaptavist)

TAGS
AUG Leaders

Atlassian Community Events