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

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

403 Forbidden while getting email user

Hi . i wanna get email adresse for a specific user by accountId and i have a 403 error 

 

getEmailUser(accountId) { 
       
let url = this.config.apiPath + "/user/bulk?accountId=" + accountId;        
return AP.request({            
url : "/rest/api/user/bulk?accountId="+accountId,
             contentType: "application/json", 
            
type: 'GET',
             Authorization: "bWJvdWF6emEuc3BlY3RydW1ncm91cGVAZ21haWwuY29tOnd6UGhpRXBWd1JTN0E0aDhrRVRyODhGRg==",
        }).then(function (data) {
            console.log(data)            
return JSON.parse(data);
        }).catch(function (error) {  
          
console.log('error email user => ' + JSON.stringify(error)) 
       }); 
    }

 i tied this url : wiki/rest/api/user/email?accountId={accountId}  

and it return the same error

error.PNG

 

2 answers

0 votes
Benjamin Community Leader Jul 13, 2021

@mehdi ,

 

The User you are using to get information, does it have full access to retrieve information. Also, is there any login issue with this user from the UI?

@Benjamin Yes he has all permissions  .

User can see all informations from this URL when he is  connected from browser

Hello @mehdi 

A 403 error tells you that the request is incorrectly formed, not that the permissions used for the request are incorrect. If the authentication credentials are incorrect or missing from the request, a 401 error is returned.

Your code has a mistake in it. If you look at where you define the URL for the request, you haven't provided the version number of which API to use, like this:

url : "/rest/api/3/user/bulk?accountId="+accountId,

However, even if you correct the mistake in your code, the API endpoint you've chosen will not tell you the user's email address, only other general information about them, because email addresses are privileged information.

Hi @David Bakkers  thank u for ur reply

I followed this documentation The Confluence Cloud REST API (atlassian.com) and it was not mentionned this url 

url : "/rest/api/3/user/bulk?accountId="+accountId,

when i tried this url , its poster to me the same error 

Hello @mehdi 

OK, sorry, I thought you were trying to make a request to the Jira REST API, not the Confluence REST API. For Confluence you don't need to supply the API version in the request URL.

However, the underlying cause of a 403 error is still that you are making an invalid request, so there is either a mistake in your code or the structure of the request.

Even if you do fix the mistake in your code and send a properly formed request to that REST API endpoint and use the appropriate permissions, it will just return a 400 Bad Request response with the message:

com.atlassian.confluence.api.service.exceptions.BadRequestException:

This API is only available to approved Connect apps

...because the documentation for that endpoint specifically says it "Returns user email addresses for a set of accountIds. This API is only available to apps approved by Atlassian, according to these guidelines." and your code does not meet the criteria described in those guidelines.

If you use a REST API test tool like Postman, as I've recommended you do in other posts elsewhere, you would have discovered that all this is true:

Annotation 2021-07-16 073638.png

I think you should spend some more time reading the documentation on how to use the REST API, what the different response codes indicate, and testing your code to see if you are sending a valid and correctly authenticated request place in the first instance.

Hello 

when i use the same url on browser or postman , they send me the result i wanted 

 

Postman.png 

Suggest an answer

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

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

120 views 4 6
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