Batch updating JQL of macros embedded in Confluence pages
Asked by Olivier B?ghain:

Hi,

I'm in a situation where I have around 300 interlinked Confluence pages in which are embedded several instance of a macros that displays the result of a JQL query (sometimes showing the number of items, sometimes the issues themselves).

I've to _on a regular basis_ update all of these JQL queries (used by the macros) and this is a very tedious and time-consuming exercice knowing that there are round 3000 queries.

So, is there a way to programmatically access the content/structure of a given Confluence page and edit/modify one of the parameters of the macro (the JQL field) and perform the update? If yes, then programmatically, I would be be able to automate such updates.

Any inputs are welcome to address this challenge ;-)

Regards

Olivier.


Answers:
author: Stephen Sifers
body: Hello Olivier and welcome to the Community!  
If you're wanting to programmatically work through multiple pages within Confluence and update the contents of the pages and macro themselves then you're most likely wanting to use the REST API. The REST API will allow you to make multiple changes to spaces, pages, and attachments through the use of scripting. With your example, I would approach this with the following endpoints:

1. GET the content of the page you want to update
   1. [GET /wiki/rest/api/content](https://developer.atlassian.com/cloud/confluence/rest/#api-content-get)
2. Take the content and adjust accordingly using the [Confluence Storage Format](https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html)
3. PUT the update into the page
   1. [PUT /wiki/rest/api/content/{id}](https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-put)

Further information about using the REST API may be found at [Confluence Cloud Developer \| REST API](https://developer.atlassian.com/cloud/confluence/rest/).

I hope this proves helpful and you're able to start updating your content easily.

Regards,  
Stephen Sifers

comments: author: Patterson Waltz
body: Hello,

Many of our Confluence pages include Jira macros to return issue lists or issue counts. When we recently renamed components in our Jira instance, the Confluence Jira macros referencing the prior component names ceased to work, similar to what [@Olivier B?ghain](/t5/user/viewprofilepage/user-id/3240895) describes in his original request.

I am attempting to use the REST API as suggested by [@Stephen Sifers](/t5/user/viewprofilepage/user-id/2145523)but am so far unable to return just the pages which I need to update via the /wiki/rest/api/content/search endpoint. My request is as follows:

```

?/wiki/rest/api/content/search?cql=macro=jira%20and%20text~%27component%20=%20Product%27&expand=space,history,version,ancestors,body.storage
```

where my CQL query is intended to return pages which include the Jira macro and whose body in Confluence Storage Format contains the text "component = Product" which I expect to find in the macro's JQL query string contents.

This approach is not working, and I'm wondering if it's a syntax problem or rather a limitation of Lucene and/or CQL, which may not be able to search based on "invisible" text such as the macro's JQL query string.  

Any further guidance would be most appreciated.

Regards,

Patterson


Tags: api

atl-adm

jql

macro