Need help with RESTClient Edited

I'm creating a ScriptRunner Groovy event script in Confluence and I'm having problems with the "response" class object below. ScriptRunner shows an error with "[Static type checking] - No such property: data for class: java.land.Object"

import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.pages.Page

def event = event as PageEvent

Page page = event.getPage()
Space space = page.getSpace()

if (space.key != 'eWebProjects') {
return
}

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*

def confluence = new RESTClient( 'https://confluence/rest/api/' )
def response = confluence.get( path: 'content' + page.id + '/page-type',
contentType: JSON)
def pageType = response.data

2 answers

I've made it a little further. I now get an error on this line:

 

def response = confluenceClient.get(path: 'rest/api/content/' + page.id + '/property/page-type')

2017-08-04 14:05:27,032 ERROR [http-nio-80-exec-273] [onresolve.scriptrunner.confluence.InnerListener] call Event handler failed: event: com.atlassian.confluence.event.events.content.page.PageUpdateEvent file: <inline script>  -- url: /pages/doeditscaffold.action | page: 24182814 | traceId: fcc54e7651b2acea | userName: er16568 | referer: http://confluence/pages/editscaffold.action?pageId=24182814 | action: doeditscaffold groovyx.net.http.HttpResponseException: Not Found         at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:263)         at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503)         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222)         at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)         at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)         at groovyx.net.http.RESTClient.get(RESTClient.java:119)         at groovyx.net.http.RESTClient$get.call(Unknown Source)             at Script844.run(Script844.groovy:39)

 

import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.pages.Page

PageEvent event = event as PageEvent

Page page = event.getPage()
Space space = page.getSpace()

if (space.key != 'eWebProjects') {
log.warn("eWebRequest Form Save Event - this is not the eWebProjects space")
return
}

import groovyx.net.http.Method
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.RESTClient
import groovy.json.JsonBuilder

def clientURL = 'http://confluence/'
def confluenceClient = new RESTClient(clientURL)

def response = confluenceClient.get(path: 'rest/api/content/' + page.id + '/property/page-type')
log.warn("eWebRequest Form Save Event: 2")

def pageType = response.class
log.warn("eWebRequest Form Save Event: 3")

log.warn("eWebRequest Form: page-type = " + pageType)

  

Did you ever find a solution? I'm trying to call the Confluence REST API as well to no avail.

 

Thanks!

This is how I fixed it.

 

import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.pages.Page

def event = event as PageEvent

Page page = event.getPage()
Space space = page.getSpace()

if (space.key != 'eWebProjects') {
// log.warn("eWebRequest Form Save Event - this is not the eWebProjects space")
return
}

//Start processing here
import java.net.HttpURLConnection;
import groovy.json.StreamingJsonBuilder;
//import java.util.logging.Logger;

String pageJson = this.getJSON("http://confluence/rest/api/content/" + page.id + "/property/page-type/", 60);

if (pageJson == null)
{
return
}

import groovy.json.JsonSlurper
import com.fasterxml.jackson.databind.ObjectMapper

//log.warn("pageJson = " + pageJson)
ObjectMapper mapper = new ObjectMapper();

Object jsonSlurper = new groovy.json.JsonSlurper().parseText(pageJson)
Map jsonResult = (Map) jsonSlurper;
def pageType = jsonResult.get("value")

if (pageType != 'eWebRequest') {
//log.warn("page-type != eWebRequest. page-type = " + pageType)
return
}

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

39 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you