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

Bitbucket API 2.0 - create deploy variables not working

Edited
oauth_resp=$(curl -X POST -u "mykey:mysecret" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials)

curl "https://api.bitbucket.org/2.0/repositories/myworkspace/mytestrepo/deployments_config/environments/{4d857618-d89d-4c4d-92a5-af70e46e4e9f}/variables" \ --request GET \ --header "Content-Type:application/json" \ --header "Authorization: Bearer $oauth_token"

UUID for the environment was got through a different GET so it's correct afaik.

response is

{"error": {"message": "Bad request", "detail": "Unexpected response body", "data": {"key": "unexpected.response.body", "arguments": {}}}}%


What I actually want to do is post deployment environment variables but that doesn't work either.

Status: 404 Headers: {'Server': 'nginx', 'Cache-Control': 'max-age=900', 'Content-Type': 'application/json; charset=utf-8', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Date': 'Sun, 08 Mar 2020 19:30:35 GMT', 'X-Served-By': 'app-1129', 'X-Static-Version': 'a856747ae2e5', 'ETag': '"d8570ff7a4314593e35e9bc69e81400a"', 'X-Render-Time': '0.0081090927124', 'Connection': 'Keep-Alive', 'X-Version': 'a856747ae2e5', 'X-Request-Count': '2694', 'X-Frame-Options': 'SAMEORIGIN', 'X-Cache-Info': 'caching', 'Content-Length': '52'} Error Response: b'{"type": "error", "error": {"message": "workspace"}}

 

API 2.0 seems to work fine for the more common get/post but fails on the less common requests. I say "less common" because the documentation is rubbish on deploy and repository variables and so I assume that no one wants to automate those things

 

4 answers

1 vote
Deleted user Mar 16, 2020

Ok. I answer myself.

 

My mistakes were two

  1. Put the url between quotes.
  2. Espace the curly brackets.

 

So, let's say your UUID is "{127cf9ca-920b-4a1f-a44d-36be6c330316}". So the request should be:

curl -u user:password "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines_config/variables/\{127cf9ca-920b-4a1f-a44d-36be6c330316\}"

 

Thanks for your hints.

The other alternative that worked for me was to use the html codes for { and } which are %7B and %7D

 

deployments_config/environments/%7B{env_uuid}%7D/variables

 

(this is python so the curly brackets you see are part of the variable subsitution

Deleted user Mar 17, 2020

Thanks for the info.

0 votes
Deleted user Mar 16, 2020

Hello @Rupert Broad and @mkleint 

 

I am in a very similar situation with pipeline_config/variables

 

I am able to get all variables with:

curl -u user:password https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines_config/variables/

 

But if I get the UUID from the response of the first command and try to get the data of a specific variable, it does not work:

curl -u user:password https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pipelines_config/variables/{UUID}

 

Very probably it is a problem with curly brackets, as @Rupert Broad  mentioned. But I don't understand what is the problem exactly.

 

Could you describe better your solution?

 

Thank you in advance.

Deleted user Mar 16, 2020

Ps: I get the same error message.

soulshake I'm New Here Oct 21, 2021

In my case I had to escape only the UUID, like:

curl -X DELETE -s -u myusername:${app_password} \
"https://api.bitbucket.org/2.0/repositories/myworkspace/myrepo/pipelines-config/caches/\{4dfb9bec-...-b9cd\}"
0 votes
mkleint Atlassian Team Mar 10, 2020

there must be something related to your curl that's causing the problem. I've tried the API with my postman setup and got back a 200 for my repository. It all looks ok to me on the surface though. Maybe some kind of escaping issue in bash?Screen Shot 2020-03-11 at 3.13.28 pm.png

@mkleintthanks for looking at this - apparently it's the curly brackets that are causing the issue. That and the poor API documentation ;)

Suggest an answer

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

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

117 views 2 4
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