Page Fields REST API

This document provides REST API details for Page fields plugin.


Get Page Fields

GET http://localhost:8090/rest/pagefields/1.0/utility/list/fields

Query parameters:

  • pageId (Number) - Confluence Page ID
  • xhtml (Boolean) - True / False to convert value to XHTML (Optional)
  • search (String) - Filter fields by name (Optional)

Response: [Status: 200]

$ curl -u"user:pass" -XGET \
http://localhost:8090/rest/pagefields/1.0/utility/list/fields/?pageId=98372
{"pageId":98372,"fieldId":8,"fieldName":"customer.manager.name","fieldValue":\
"Swetha Venkat Prasad","lastUpdated":1525004706342}
$


GET http://localhost:8090/rest/pagefields/1.0/utility/list/field

Query parameters:

  • pageId (Number) - Confluence Page ID
  • fieldId (Number) - Confluence Page Field ID

Response: [Status: 200]


Get Page Fields History

GET http://localhost:8090/rest/pagefields/1.0/utility/list/history

Query parameters:

  • fieldId (Number) - Confluence Page Field ID


Add Page Field

POST http://localhost:8090/rest/pagefields/1.0/utility/add/field

Required Schema Fields:

  • pageId (Number) - Confluence Page ID
  • fieldName (String)
  • fieldValue (String)
  • history (Boolean) - Optional

Response: [Status: 200]

$ curl -u"user:pass" -XPOST -H "Content-Type: application/json" --data '{"pageId":342345, \
"fieldName":"confidential.agreement.receive.date", "fieldValue":"2017-05-02"}' \
http://localhost:8090/rest/pagefields/1.0/utility/add/field
{"field":10,"message":"[Info] Added New Page Field"}
$


Update Page Field

POST http://localhost:8090/rest/pagefields/1.0/utility/update/field

Required Schema Fields:

  • pageId (Number) - Confluence Page ID
  • fieldName (String)
  • fieldValue (String)
  • history (Boolean) - Optional

Response: [Status: 200]

$ curl -u"user:pass" -XPOST -H "Content-Type: application/json" --data '{"pageId":342345, \
"fieldName":"confidential.agreement.receive.date", "fieldValue":"2017-05-03"}' \
http://localhost:8090/rest/pagefields/1.0/utility/update/field
{"field":10,"message":"[Info] Updated Page Field"}
$

Note. Update creates field if not exists.


Force Page Space Field

POST http://localhost:8090/rest/pagefields/1.0/utility/update/field/force

Required Schema Fields:

  • pageId (Number) - Confluence Page ID
  • fieldId (Number) - Confluence Page Field ID
  • fieldName (String)
  • fieldValue (String)
  • history (Boolean) - Optional

Response: [Status: 200]

Note. This API helps to rename field name.

$ curl -u"user:pass" -XPOST  -H "Content-Type: application/json" --data '{"spaceKey":"DT", \
"fieldId":"5", "fieldName":"project.security.key", "fieldValue":"xxxxxxx"}' \
http://localhost:8090/rest/pagefields/1.0/utility/update/field/force
{"field":5,"message":"[Info] Updated Space Field"}
$


Delete Page Field

DELETE http://localhost:8090/rest/pagefields/1.0/utility/remove/fields/page/id/{pageId}/field/id/{fieldId}

DELETE http://localhost:8090/rest/pagefields/1.0/utility/remove/fields/bulk/page/id/{pageId}

$ curl -u"user:pass" -XDELETE \
http://localhost:8090/rest/pagefields/1.0/utility/remove/fields/page/id/98372/field/id/10
{"field":10,"message":"[Info] Removed Page Field"}
$
Groovy Example
import org.apache.http.HttpEntity
import org.apache.http.HttpStatus
import org.apache.http.client.methods.CloseableHttpResponse
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
import org.apache.log4j.Level

log.setLevel(Level.DEBUG)

HttpGet method = new HttpGet("http://localhost:8090/rest/pagefields/1.0/utility/list/fields/page/id/3145752")
method.setHeader("Authorization", "Basic YWRtaW46YWRtaW4=")

try {
    CloseableHttpClient client = HttpClients.custom().build()
    CloseableHttpResponse response = client.execute(method)

    log.debug("response code: " + response.getStatusLine().getStatusCode())

    if(response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        log.warn("Method Failed: "+ response.getStatusLine().getStatusCode())
    }else{
        HttpEntity entity = response.getEntity()
        String responseBody = EntityUtils.toString(entity)                  
        log.debug("Response Body: "+ responseBody)
    }

} catch (IOException ex) {
    log.error(ex)
} finally {
    method.releaseConnection()
}

Output in atlassian-confluence.log

2018-05-18 21:14:23,127 DEBUG [http-nio-8090-exec-9] [onresolve.scriptrunner.runner.ScriptRunnerImpl] call response code: 200
2018-05-18 21:14:23,130 DEBUG [http-nio-8090-exec-9] [onresolve.scriptrunner.runner.ScriptRunnerImpl] call Response Body: [{"pageId":3145752,"fieldId":30,"fieldName":"xxxx","fieldValue":"xxxx","lastUpdated":1524997529545},{"pageId":3145752,"fieldId":28,"fieldName":"customer.source","fieldValue":"public static void main(String[] args) {\r\n    System.out.println(\"Hello World!\");\r\n}","lastUpdated":1522299682381},{"pageId":3145752,"fieldId":29,"fieldName":"customer.feedback","fieldValue":"So far good.","lastUpdated":1522299674396},{"pageId":3145752,"fieldId":27,"fieldName":"customer.name","fieldValue":"Swetha Venkat Prasad","lastUpdated":1522299546648}]