How can I post a new issue to JIRA project using axios post?

Som Sarkar July 7, 2020

Hi Experts,

I'm running a React JS app, and from there, I'm trying to create a new issue under a project in the JIRA using axios with post method. But getting error with status : 403 (Forbidden) and response : XSRF check failed.

Please refer to below the code:

post rest api issue.PNG 

So, could you please help me in fixing the POST method with data to be posted as shown in the screenshot above?

Please note that, axios with GET method is working fine with url like below

let url = "https://cors-anywhere.herokuapp.com/https://jsw.ibm.com/rest/api/2/issue/QAHUB-1?fields=description";

3 answers

1 vote
safinaz
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!
August 7, 2020

I had the same problem and after checking for the whole day I found that the problem with the request is the user-agent in the header.

I was using chrome to test creating a request by Jira service desk api and I got the same error 403 (Forbidden)

I just test my app on Safari and Firefox and It works fine

0 votes
safinaz
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!
August 6, 2020

@Som Sarkar I'm facing now the same issue.

Did you find a solution?

0 votes
Italo Qualisoni [e-Core]
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.
July 7, 2020
Som Sarkar July 7, 2020

@Italo Qualisoni [e-Core] I've checked that doc but couldn't get much help as my use case is with axios. So I've shared the code in the screen shot and kindly let me know what to adjust to get this working.

Regards

Italo Qualisoni [e-Core]
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.
July 7, 2020

I think you need to add the X-Atlassian-Token header to each request, setting the value to no-check

headers:{
'X-Atlassian-Token':'no-check'
}

 Also I'm not sure why you are using https://cors-anywhere.herokuapp.com instead of the direct url.

Som Sarkar July 7, 2020

@Italo Qualisoni [e-Core]I tried with below additional in headers, still getting same error.

 'X-Atlassian-Token':'no-check'

 

Please help if there is any other way to correct the POST method using axios.

For your info, we're using https://cors-anywhere.herokuapp.com instead of the direct url to overcome CORS policy issue as per reference from this below link.

Overcome CORS issue 

Italo Qualisoni [e-Core]
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.
July 8, 2020

Hi @Som Sarkar ,

Can you try the command using Postman?

Italo Qualisoni [e-Core]
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.
July 8, 2020

Also I think you should run the code in your nodejs backend instead of running on browser.

Suggest an answer

Log in or Sign up to answer