Hi!
We are trying to create a Groovy script that is triggered by an Insight automation rule that when a user is added to an object of a specific type, it automatically also adds users to all related objects of a different specific type.
For example, when on a Collaboration Partner object a user is added, for all related Organizations add those Organizations to the user. Vice versa for deleting users.
What we have now is a script that is able to do the 'add' function, but we are facing some challenges with the 'delete' function. The challenge is that the REST-API endpoint to remove users from an organisation requires the users to be included in the body of a DELETE request. This causes a problem in our Groovy script, because neither the HTTPBuilder nor the RestClient supports adding a body to a DELETE request. See example below.
```import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import groovy.json.\*
import com.atlassian.jira.component.ComponentAccessor
def url = ComponentAccessor.getApplicationProperties\(\).getString\("jira.baseurl"\)
def endpoint = "/rest/servicedeskapi/organization/1/user"
def username = "admin"
def password = "password"
def encoded = "$username:$password".toString\(\).bytes.encodeBase64\(\).toString\(\)
def httpBuilder = new HTTPBuilder(url\)
def jsonSlurper = new JsonSlurper\(\)
def formattedJson
def returnResponse
try \{
httpBuilder.request(Method.DELETE, ContentType.JSON\) \{
headers."Authorization" = "Basic $encoded"
headers."Accept" = "application/json"
headers."X-ExperimentalApi" = "opt-in"
body = \[usernames: \['some@user.nl'] ]
uri.path = endpoint
response.success = \{ response, json \->
if \(json\) \{
returnResponse = json
formattedJson = JsonOutput.toJson(json\)
}
}
response.failure = \{ resp, data \->
if \(data\) \{
returnResponse = \[error: "Failed to make http request to $url/$endpoint", statusLine: resp.statusLine, data: data]
} else \{
returnResponse = \[error: "Failed to make http request to $url/$endpoint", statusLine: resp.statusLine]
}
}
}
} catch(e\)\{
returnResponse = \[error: "Some other error occured: $e"]
}
if \(formattedJson\) \{
log.warn(formattedJson.toString\(\)\)
} else \{
log.warn(returnResponse.toString\(\)\)
}```Which returns:
```error:Some other error occured: java.lang.IllegalArgumentException: Cannot set a request body for a DELETE method```
Do you know if there is a way to send a DELETE request with a body in Groovy or is there another endpoint available that doesn't require a DELETE method with a body?