Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Embed JIRA ISSUES Macro to Rest API Content

Sathish Ramani February 11, 2018

https://confluence.atlassian.com/confcloud/jira-issues-macro-724765217.html

 

Hi guys, i can embed issues via the JIRA issues filter.

But how can i do this programatically, via the rest api.

 

Let's say, i want to create a new page in confluence via 

POST https://carousell.atlassian.net/wiki/rest/api/content/

 

What is the exact thing to do for the JIRA ISSUES FILTER?

3 answers

2 votes
Josie Salcedo April 23, 2018

Is there documentation somewhere on how to do this through python?

Orlando Jurcone March 19, 2019

Hello Josie,

 

I just did this with Python.

Here is the code

#open source.txt file

fSource = open("source.txt", "r")
source = fSource.read()

#Rest API

url = "https://newconfluence.company.org/rest/api/content"

data = {"type":"page", "ancestors":[{"type":"page", "id":2687111}], "title":"Test", "space":{"key":"WE"},"body":{"storage":{"value":source,"representation":
"storage"}}}
headers = {'Content-Type':'application/json'}

r = requests.post(url, data=json.dumps(data), headers=headers, auth=('user', 'password'))

 

#in the source.txt I have the following code

 <p>
<ac:structured-macro ac:name='jira'>
<ac:parameter ac:name='columns'>key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution</ac:parameter>
<ac:parameter ac:name='key'>WEL-17779</ac:parameter> </ac:structured-macro>
</p>

#WEL-17779 - is the Jira ticket key name

#That's it. I hope it helps

Omisha_Gupta
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 9, 2020

I tried this method, didn't work out for me. However, I have figured out another way for this simple post request.

Other steps remain the same, making source files with the same syntax.

from atlassian import Confluence, Jira

fSource = open("source.txt", "r")
SourceFileToImport = fSource.read()

status = confluence.create_page(
space='space-name',
title="titlename",
body=SourceFileToImport)

It works like a charm for me!

2 votes
Maarten Cautreels
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2018

Hi Sathish,

Confluence pages are basically some sort of html containing special snippets of Confluence Markup. If you'd like to add a JIRA macro you could use the following snippet of Confluence Markup in your POST body:

<ac:structured-macro ac:name="jira" ac:schema-version="1">
<ac:parameter ac:name="columns">key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution</ac:parameter>
<ac:parameter ac:name="maximumIssues">20</ac:parameter>
<ac:parameter ac:name="jqlQuery">JQL_QUERY</ac:parameter>
<ac:parameter ac:name="serverId">JIRA_SERVER_ID</ac:parameter>
</ac:structured-macro>

If you're wondering where you can find the Server Id, you can use the following Knowledge Base article: Finding your Server ID.

Hope this helps.

Best,

Maarten

Btw: I've tested this on JIRA Server. Could work a little different on Cloud but is worth trying. Please do let us know if it worked!

Sathish Ramani February 11, 2018

I managed to do it on cloud eventually using,

<ac:structured-macro ac:name='jira'><ac:parameter ac:name='columns'>key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution</ac:parameter><ac:parameter ac:name='key'>ABC-123</ac:parameter> </ac:structured-macro>

 

However, is there any confluence page by jira that lists all macro? It's dissapointing to see that 'ac:structured-macro', 'ac:name='jira' are no where to be found in confluence wiki :(

Maarten Cautreels
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2018

Hi Sathish,

Looks very similar to the syntax on Server (except for the serverId). :-)

There's a list with all macro's but that does not contain all technical values: Macros. On the other hand, the list of macros also differs depending on the installed addons.

If you'd like to see a list of all macros in use on your Confluence you can go to: https://<YOURSITE>.atlassian.net/wiki/admin/pluginusage.action

That page will show a list of all macros (their technical name) and the number of times they have been used.

Best,

Maarten

Sathish Ramani February 11, 2018

Thanks for the reply! That page helps alot! It took me so long to find the macro name which is jira in this case as it wasn't documented anywhere. But this page is definitely helpful! Thanks!

DaveTheRave
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 27, 2018

Any way to make this list static and not dynamic with a refresh button?

0 votes
naveenkumar_dp
Contributor
December 9, 2019

Hi,

Is there any documentation is there for JAVA?

Thanks

Naveen

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events