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

Access Bitbucket API from Client/Browser (CORS access support)

Marko Tomljenovic March 22, 2019

Hello,

we are currently developing a web application that should access (only read) some data (repos, commits and merge requests) from Bitbucket projects via some javascript code.

Now we have read that Bitbucket does not really support CORS access.

But I also found this page: https://developer.atlassian.com/bitbucket/api/2/reference/meta/cors-hypermedia

Can you tell me if there is a way to accomplish what I need?

Thank you

1 answer

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 25, 2019

Hello Marko,

Bitbucket supports CORS when used within the REST API as an additional option. The reference documentation you provided is the same source we use internally for reference material. This documentation also applies to Bitbucket cloud REST API v2. With this said, when making your API calls, you will need to provide the options to include your CORS information.

To better help, are you running into an errored response or are you receiving an error message? Any error message, log or output would help us have a further context in the blockers your experiencing.

We look forward to your response so we can help get your Bitbucket access up and running!

Regards,
Stephen Sifers

seshi reddy March 29, 2019

Hello Stephen,

We are trying to Access the Bitbucket Rest services directly via web browser(Browser is making call to bit bucket service  directly no back end service interaction)

 

We are getting below exception :

XMLHttpRequest at 'http://hostA:7990/rest/api/1.0/projects/FIR/repos/demo/commits'
from origin 'https://hostA:8080'
has been blocked by CORS policy: Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

 

also above information and this information https://jira.atlassian.com/browse/BSERV-10589

is contradicting

 

Also CORS header is not present in response, please .

2019-03-29_14h20_58.png

Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 1, 2019

Hello Seshi,

Thank you for sending over your response errors and the screenshots of your attempt. Something between your communication with the Bitbucket instance and your call is triggering CORS. It might something network or device related which is causing this.

With this said, you will need to include CORS headers within your API calls for them to respond successfully. Could we please attempt an API call with the CORS headers?

Here is an example:

curl -i https://api.bitbucket.org -H "origin: http://bitbucket.com" -X OPTIONS

We look forward to your response to get your API calls working.

Regards,
Stephen Sifers

seshi reddy July 26, 2019

Hello Stephen, 

Thank you for your replay.

i am trying something like below.

I have a web application(Demp App) which is running on port 7443 and it has some UI and from UI we are making call as shown below

i.e, it will not hit the Demo App, but it tries to connect bibucket server and it gives CORS 

 

xhr.get("http://localhost:7990/rest/api/1.0/users/UserId, {
headers: {
"X-Atlassian-Token": "no-check",
"Access-Control-Allow-Origins" : "*",

"Access-Control-Allow-Methods":"OPTIONS",

"Authorization": "Bearer "+accessToken
}});

 

Please refer below screenshot

CORS_Issue.png

 

Thanks in Advance.

Seshi

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events