Forums

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

Get 403 Forbidden error with rest api

James Abens
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!
December 29, 2023

I have created a randomized quiz in a Confluence HTML Macro using javascript. The quiz is a knowledge check for users who wish to gain access to an application they have taken training for.

At the conclusion of the training, I want to either add a comment to an existing JIRA, or create a new JIRA, using the rest api or use automation with a webhook to generate a JIRA. 

I am able to use get in the rest api for myself or a specific JIRA and display the returned values, so that is working fine. However, when I try the 'POST' method to add a comment, add an issue, or use a webhook, I get 403 forbidden. I was getting a CORS error orignally, but I resolved that through a proxy. Now I get the 403 forbidden error.

The get doesn't even require authorization in the header for some reason.

I've tried using 'Basic ' + btoa(userName + ':' + accessToken) in the header, but to no avail. I've also tried 'Bearer ' + accessToken, and have tried my password instead of the personal access token. All results in 403 forbidden.

Anyone have ideas how to resolve?

function updateJiraIssue() {
   const apiUrl = 'https://confluence.net/plugins/servlet/applinks/proxy?appId=0f4bdff9-e31c-37bc-ae42-&path=/rest/api/latest/issue/XFCH-6365/comment';     
   const accessToken = 'xxxx';
   const userName = 'username';

   const data = {
      body: 'test comment'
   };

   fetch(apiUrl, {
      method: 'POST',
      headers: {
         'Authorization': 'Basic ' + btoa(userName + ':' + accessToken),         
         'Content-type': 'application/json',
         'Accept': 'application/json'
      },
      body: JSON.stringify(data)
   })
}

1 answer

0 votes
Florian Bonniec
Community Champion
January 3, 2024

HI @James Abens 

 

Does the user used have comment permission ?

 

Regards

Suggest an answer

Log in or Sign up to answer