Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to make a GET request to JIRA REST API from a Confluence Cloud Macro with fetch()? Edited

This is more of a technical question but the Developer Community has been pretty unhelpful thus far.

I want to make a GET request to the JIRA REST API from a Confluence Cloud macro I'm developing for my internship. Because Atlassian doesn't support cross-platform requests natively, I have to make the request outside of routes/index.js and instead in a script tag of the .hbs file in my views folder. I'm prototyping so I'm only using basic auth as detailed in the documentation. When I test it outside my app with the command line with curl and also straight up in my browser while I'm logged into Confluence I'm able to get the issues I want to return. But... when I attempt to make the request form within the .hbs file an OPTIONS request gets made instead and the Authentication header with the username and password that I set is not there...

This is the code that I'm using....

let url = 'https://site.atlassian.net/rest/api/3/search'


let h = new Headers(); h.append('Accept', 'application/json');


let encoded = window.btoa('USERNAME:APITOKEN'); let auth = "Basic " + encoded;

h.append('Authorization', auth)


let req = new Request(url, { method: 'GET', headers: h })


fetch(req)

.then( (res) => {

return res.json().then( (data) => {

if(res.ok) { return data; } else { return Promise.reject({status: res.status, data}); } }); }) .then((data) => { console.log(data); })

 

Does anyone know why this is happening?

 

1 answer

The url you use should have `https` instead of `http`.  Hope that helps.

Didn't fix it unfortunately. But thank you for reminding me.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

680 views 7 19
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you