Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi Everyone, I am able to make a POST request from Jira to Confluence with the help of this code, does any one know how can i modify the below part of the code to make a GET request from Jira to Confluence.
authenticatedRequestFactory
.createRequest(Request.MethodType.POST, "rest/api/content")
.addHeader("Content-Type", "application/json")
.setRequestBody(new JsonBuilder(params).toString())
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
if(response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.getResponseBodyAsString())
}
else {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
}
}
})
Hello @Vineet Kumar
What is it that you plan to achieve by doing the Get request?
For the doing the get request you do the change here
.createRequest(Request.MethodType.GET, "rest/api/content")
And also make required changes in the response handler callback code.
Tarun is right, try something like this and replace PAGE_ID_HERE with the ID of the page you want to get.
authenticatedRequestFactory
.createRequest(Request.MethodType.GET, "rest/api/content/PAGE_ID_HERE")
.addHeader("Content-Type", "application/json")
.execute(new ResponseHandler<Response>() {
@Override
void handle(Response response) throws ResponseException {
if(response.statusCode != HttpURLConnection.HTTP_OK) {
throw new Exception(response.getResponseBodyAsString())
}
else {
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
}
}
})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Tarun and Bastian, I would like to GET the content of a confluence page and copy it to a variable from the Jason output, but the method is returning null on the script console, May i know which variable on the above script will hold the result in the form of Jason from which i can get the content written on the page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Change
def webUrl = new JsonSlurper().parseText(response.responseBodyAsString)["_links"]["webui"]
To new
def body = JsonSlurper().parseText(response.responseBodyAsString)["body"]
then you can access the body in storage format with
body.storage.value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bastian Stehmann I'm using your code to make it possible for users in a Jira Service Desk to create their own Confluence Space by just filling in fields in the Service Desk.
is there any way, so that a user without admin rights can use the Rest Call in order to create a Confluence Space? is there any method in the authenticatedRequestFactory, that might make this possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.