Unable to create an environment variable...

curtisa January 1, 2021

Hi all,

I've tried for probably hours to get the below working but I just can't seem to be able to create an environment variable. The API I'm calling is ...

$ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <token>" -d '{"key": "mytestkey", "value": "value1", "secured": false }' https://api.bitbucket.org/2.0/repositories/<username>/<repo-slug>/deployments_config/environments/{environment UUID in curly brackets}/variables

The error I get is : 

{"error": {"message": "Not found", "detail": "The value provided is not a valid uuid."}}

The environment UUID I use in the URL is what is returned from a GET on

https://api.bitbucket.org/2.0/repositories/<username>/<repo-slug>/environments/

Can anyone see what I'm doing wrong pls (I think I'm following the API docs at : https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/deployments_config/environments/%7Benvironment_uuid%7D/variables ). I'm not sure the API docs are strictly correct on that URL above because I don't know how you can include a UUID in the payload when you're creating a variable. 

 

Many thanks for any help / tips...

 

2 answers

1 accepted

2 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 5, 2021

Hi @curtisa ,

You will need to encode the characters for the curly brackets in order for this to work.

{ should be replaced with %7B and } with %7D

An example call:

curl -X POST -H "Content-Type: application/json" -u username:app-password 
-d '{"key": "mytestkey", "value": "value1", "secured": false }' https://api.bitbucket.org/2.0/repositories/my-workspace/my-repo/deployments_config/environments/%7B26e47eac-2770-4b69-8f23-92634d03a443%7D/variables

where 26e47eac-2770-4b69-8f23-92634d03a443 is the UUID of my Pipelines environment.

Could you please give this a try?

Please feel free to let us know if it works or if you need further assistance.

Kind regards,
Theodora

curtisa January 10, 2021

Hi Theodora,

Yes that fixed it many thanks.

Kind regards

Alex

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 13, 2021

Hi Alex,

That's good to hear, thank you for the update and you are very welcome!

Kind regards,
Theodora

2 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 1, 2021

Hi! 

How did you get the uuid ? 

curtisa January 1, 2021

Hi,

By calling

https://api.bitbucket.org/2.0/repositories/<username>/<repo-slug>/environments/

and then picking the uuid value of the environment I want to set the variable for, i.e... 

"uuid": "{abcdefg-12345-abcd-1234-abc1234567890}"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events