How to call Bitbucket Server REST endpoints from within a Bitbucket Server plug-in?

Michael T.
Contributor
March 22, 2017

Hi,

I need to use some Bitbucket Server REST endpoints from within a Bitbucket Server plug-in (because they are not exposed as Java API services). How can I achieve that?

There must be a way to authenticate myself when calling these REST endpoints. For JIRA, there seams to be a possibility to authenticate as the current user by using JSESSIONID. Is there also a way to achieve this for Bitbucket Server?

Thanks in advance,

Michael

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Felix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 22, 2017

The LFS REST endpoint, just like the LFS Java API, is currently not public. While you can technically use the endpoint, no API guarantees are made, and the endpoint may change behaviour, structure, request and/or responses in any release. 

The reason calling REST from the backend, other than being unnecessarily slow by introducing a network call for a local operation, is that in a clustered environment, you cannot guarantee that the request will end up on the same node as the one making the request. 

Depending on the configuration of the cluster (session replication vs. sticky sessions) it can cause unpredictable behaviour (like no local session existing for the user you are making the request as).

Making the REST request using basic authentication would work (as it does not rely on sessions), but it'd require user credentials, and the information on which user performed the action would be lost.

 

If I may ask, what problem are you trying to solve with your plugin? 

0 votes
Michael T.
Contributor
March 22, 2017

Thanks for your feedback. Yes, I try to call the REST endpoint from a Java plug-in. What I need is access to the Git LFS setting (enable/disable) which unfortunately is not exported for plug-ins (internal API only). But the REST endpoint is available. Unfortunately, my plug-in's use case doesn't allow using the JavaScript API. Any suggestions on how to accomplish this? Could you please explain why this would not work in a cluster?

0 votes
Felix
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 22, 2017

Could you provide a bit more information on what you're trying to achieve? Which REST endpoint are you trying to call and what information do you need?

Where are you trying to call the REST endpoint from? The backend (ie. from your Java code in the plugin)? If so, I'd highly recommend you not do that, as it will not work consistently in a cluster. 

If you're trying to call a REST endpoint from UI code, we provide a JavaScript API, which lets you make authenticated calls to the REST API. 

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events