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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,603
Community Members
 
Community Events
176
Community Groups

Bitbucket code search api is not working

I am trying to use the bitbucket code search API and I am getting 401 error "Token is invalid or not supported for this endpoint."

I created a repository access token and can access this particular URL 'https://api.bitbucket.org/2.0/repositories/nasrulrules' with an authorization bearer token in the header without any issue.

But I couldn't access the code search API with the same token. I am having an invalid token issue. My code search api - 

I am following the above two articles. In these articles it is mentioned like 'GET /2.0/teams/{username}/search/code'

what username I should give? I already tried with 'nasrulrules'

In the first article I am seeing the api you provided and what is "%7B6f461d1e-a3dd-433b-a0e3-7a69daf6ea47%7D" ? 

https://api.bitbucket.org/2.0/teams/%7B6f461d1e-a3dd-433b-a0e3-7a69daf6ea47%7D/search/code?search_query=repo%3Aelasticsearch%20QueryBuilders

 

kindly provide more suggestions on this.

 

Note: This is a private repository and I am the only user in it. 

 

 

 

 

1 answer

0 votes
Patrik S Atlassian Team Jan 10, 2023

Hello @nasrulrules ,

Welcome to Atlassian Community!

The 401 Authorization error usually means that your credentials are either invalid or do not have sufficient permissions to execute that action. If you created the token using an Oauth consumer, could you try to check all the scopes when creating the consumer to make sure you have the necessary permissions when doing the API call? 

Screenshot 2023-01-10 at 4.33.50 PM.png

As for the endpoint, Bitbucket Cloud API provides two different endpoints for code search, with the difference them being the type of the workspace: personal or shared (team) workspaces.

If you want to Code Search in a personal workspace : 

  • Search code in a user's repository 

    Example API call :
    curl --request GET \

      --url 'https://api.bitbucket.org/2.0/users/<personal workspace id>/search/code?search_query=foo+repo:demo' \

      --header 'Authorization: Bearer <Bearer token>' \

      --header 'Accept: application/json'

If you want to Code Search on a shared workspace : 

  • Search code in a team's repository 

    Example API call : 
    curl --request GET \

      --url 'https://api.bitbucket.org/2.0/teams/<shared workspace id>/search/code?search_query=foo+repo:demo' \

      --header 'Authorization: Bearer <Bearer token>' \

      --header 'Accept: application/json'

You're also welcome to check Difference between shared and personal workspaces for more details on each type of workspace.

Hope that helps! Let me know in case you're still running into issues with that endpoint.

Thank you, @nasrulrules.

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events