• Community
  • Products
  • Confluence
  • Questions
  • How can I add some custom JavaScript or a little snippet that will use the Confluence API to grab current user's info to a Confluence page?

How can I add some custom JavaScript or a little snippet that will use the Confluence API to grab current user's info to a Confluence page?

I'm a developer working on a project and have never used Confluence before. Is there a way to add some custom javascript or a little snippet to a confluence page to let me grab the current user's info and then pass that along?


Details:
1) Confluence web page has a button.
2) When a user clicks that button, I want to use the confluence api to grab the user's info, open a new window to the url with the user's info attached as the query string.

 

Basically, I just want to know if there's a way add a snippet using the confluence api. I have the api method I need, but am having trouble figuring out how it can be added to the page. One of our customer's uses Confluence for their company and is requesting this feature.

1 answer

Hi MacGregor, 
If I understand correctly what you are wanting to do, to add JavaScript into a Confluence page you need to insert the HTML macro. To do this go to the Confluence editor, click Insert > Other Macros, and search for HTML macro. Then insert it into the page. Inside the HTML macro, you can then add the JavaScript code.


I hope this helps

Well the issue is that the steps to turn on the html macro don't work.

  1. Go to  > Add-ons.

  2. Select System from the drop down and search for the Confluence HTML Macros add-on.
  3. Expand the add-on and enable the html (html-xhtml) module.

The only thing listed that has 'html' in it is 'Atlassian XHTML'.  

 

If you do what you say, the only html macros listed are as follows:

1) HTML Comment

2) HTML Image

3) HTML Table

4) List Item (li)

5) Ordered List (ol)

6) Table Body (tbody)

7) Table Cell (td)

8) Table Head (th)

9) Table Head (thead)

10) Table Rod (tr)

11) Unordered List (ul)

 

None of these help me out.  So neither the steps to turn on the HTML macro work, nor do the steps for adding it (I would presume since it's not enabled in the first place).

Hi MacGregor, 
Are you using Cloud or Server?

If you are using Cloud, you won't be able to use the HTML macro. Although, you can use the Atlassian Connect (https://developer.atlassian.com/static/connect/docs/latest/index.html). This allows you to build add-ons to customise your Atlassian products. 

If you are using Server, then you may need your admin to enable the html macro. To do this, please refer to this document: https://confluence.atlassian.com/conf54/confluence-administrator-s-guide/managing-add-ons-and-macros/enabling-and-configuring-macros/enabling-html-macros

Like 1 person likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,022 views 14 12
Join discussion

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