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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.