Preflight CORS in JIRA REST API (GET request with headers)

Julien LeGa September 21, 2018

Hello,

I'm trying to use the REST API JIRA to catch informations about my installed plugins. To do that, I created an Angular 6 project and I used HttpClient to do an GET request wich I pass my basic authorization in the header.

 

I got an Preflight cors error..

app.component.ts

const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Authorization': 'Basic ' + btoa('xxx:xxx')
})
};
this.httpService.getHttp('https://jira.mydomain.com/rest/plugins/1.0/', httpOptions)
.subscribe(jsonPlugins => {
this.filterPlugins(jsonPlugins);
this.setPluginsLastestVersion();
});

http.service.ts

getHttp(url: string, httpOptions: {}) {
return this.http.get(url, httpOptions);
}  

I'm completly lost. If someone could help me

Have a good day, thanks

1 answer

0 votes
Santwana Sarangi {Appfire}
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.
September 23, 2018

 

Hi Julien,

As you are using angular js to access the plugin rest api installed in the jira, you are trying to make a Cross-origin HTTP request. In this case, the jira server has to allow the client (from where get request is made) to receive the response that it is sending.

So I guess, you need to add this header parameter 

Access-Control-Allow-Origin': '*'

in the response that you are sending from your plugin.

For more information regarding CORS, please check the following url

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Also, I could find something similar in the atlassian community. Below is the link

https://community.atlassian.com/t5/Answers-Developer-Questions/Enable-CORS-in-JIRA-REST-API/qaq-p/553997

Hope this helps.

 

Thanks,

Santwana

Julien LeGa September 23, 2018

Thanks for the response,

 

I'm not using Angular JS but Angular2 and I'm not working on a jira plugin but i'm trying to access informations about my installed plugins (https://jira.softcom.pro/rest/plugins/1.0/) from my website.

There is already in my HTTP request header.. That's why I don't understand where is the problem

'Access-Control-Allow-Origin': '*'

 Have a nice day

dur4791 July 5, 2021

Any updates on this issue? I'm facing the same issue.

Suggest an answer

Log in or Sign up to answer