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
Community Members
Community Events
Community Groups

Bitbucket API 2.0 - create deploy variables not working

oauth_resp=$(curl -X POST -u "mykey:mysecret" -d grant_type=client_credentials)

curl "{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 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 "{workspace}/{repo_slug}/pipelines_config/variables/\{127cf9ca-920b-4a1f-a44d-36be6c330316\}"


Thanks for your hints.

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 '{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",
"value": "us-east-1",
"secured": false

Thanks for looking.

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




(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{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{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.

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

curl -X DELETE -s -u myusername:${app_password} \
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

Atlassian Community Events