Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bitbucket API 2.0 - create deploy variables not working

Rupert Broad
Contributor
March 9, 2020
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

 

5 answers

1 vote
Deleted user March 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.

0 votes
Casey Wise
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 24, 2022

The value provided is not a valid uuid.

When attempting to Create a variable for an environment, I'm getting the following, despite my best efforts.
{
"error": {
"message": "Not found",
"detail": "The value provided is not a valid uuid."
}
}
Not entirely confident with how I found my environment I guess it's included in the return List variables for an environment endpoint request.

I've tried every combination of a curly-brace-wrapped uuid in the payload and in the endpoint url. 

Current curl

curl --location --request POST 'https://api.bitbucket.org/2.0/repositories/workspace/repo_slug/deployments_config/environments/{envrionment_uuid}/variables' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic base64_encoded_app_un:pw' \
--data-raw '{
"type": "pipeline_variable",
"uuid": "environment_uuid",
"key": "AWS_DEFAULT_REGION",
"value": "us-east-1",
"secured": false
}'

Thanks for looking.

0 votes
Rupert Broad
Contributor
March 17, 2020

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 March 17, 2020

Thanks for the info.

0 votes
Deleted user March 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 March 16, 2020

Ps: I get the same error message.

soulshake
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 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
Atlassian Team members are employees working across the company in a wide variety of roles.
March 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

Rupert Broad
Contributor
March 11, 2020

@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
AUG Leaders

Atlassian Community Events