How can we display Bitbucket commit version in php page

519 views Asked by At

How can we get bitbucket last commit version in php page. I tried https://api.bitbucket.org/2.0/repositories/user/repositoryname but getting access forbidden.also nothing explained anywhere about header.

1

There are 1 answers

0
eis On

This is the api for latest commits: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits

Authentication is explained here. There are several options there. To me, the app password option sounds like it's the best suited one for your use case.

App password is created as follows (quote from the link above):

To create an app password:

1. Select Avatar > Bitbucket settings.
2. Click App passwords in the Access management section.
3. Click Create app password.
4. Give the app password a name related to the application that will use the password.
5. Select the specific access and permissions you want this application password to have.
6. Copy the generated password and either record or paste it into the application you want to give access. The password is only displayed this one time.

As per this page, using it would be like

curl --user bitbucket_user:app_password url

Which you should be able to translate to php quite easily as it's just basic authentication and normal http get.