You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I would like to modify deployment environments within a repo using the API.
The most appropriate method is:
/2.0/repositories/{workspace}/{repo_slug}/environments/{environment_uuid}/changes/
However the documentation does not specify a body to POST. How do we use this API call? Any examples what params to place after "changes"?
Worked around guessing a payload by snooping Network traffic in browser console, when performing the same action on the bitbucket UI.
API docs are not 100% complete without some of this guess work
I am having the same issue. Could you clue me in on the required parameters to include in the post body?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nvm I found the same info in network tab
for anyone else looking try this post body with curl
`-d '{"change": {"name": "Test-42"}}`
It is still unclear to me which attributes of the deployment can be changed via the REST API. I can update the name but attempts to modify other params have given me the following error:
`{"key": "deploy-service.environment.change-not-supported", "message": "The requested change is not allowed.", "arguments": {}}`
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Heather Young A late - but nonetheless BIG - "Thank You" for posting this! I went almost insane with this api-call not doing what it is supposed to.
I just wonder: How can that still not be properly documented by Atlassian meanwhile? I tried several resources like OpenApi/Swagger., the official Api-Reference and some more until i finally found this post several hours later.
By the way: It seems that (meanwhile?) other environment-parameters can also be updated. At least it worked for me for all params that i tried so far.
In my script, i now detect if an environment already exists -> if yes, i just wrap the body-json (that i use for the create-api otherwise) in an element called "change".
For me the "restrictions" block was the most important to update, besides maybe the name.
If anyone is interested, here is that specific part of my (working) Powershell script:
# Get environment uuid if env. already exists
$env_uuid = ($existing_environments | Where-Object {$_.name -eq "Test-Env"}).uuid | Get-Unique
# Set payload
$body = @{
type = "deployment_environment"
name = "Test-Env"
environment_type = @{
type = "deployment_environment_type"
name = "Test"
}
restrictions = @{
type = "deployment_restrictions_configuration§
admin_only = true
}
}
# Create or update environment
if (!$env_uuid) {
# Convert body to json
$body = $body | ConvertTo-Json -Depth 10
# Invoke Rest-Api - Create
Write-Host "Creating environment Test-Env"
Invoke-RestMethod -Method 'POST' -Uri $api_url -Authentication Bearer -Token $token -ContentType 'application/json' -Body $body | out-null
}
else
{
# If update, wrap body with element "change". Thanks to Atlassian for not documenting this properly...
$body = @{ change = $body } | ConvertTo-Json -Depth 10
# Set endpoint for update (add env. uuid)
$api_url_env = $api_url + "$env_uuid/changes/"
# Invoke Rest-Api - Update
Write-Host "Updating environment Test-Env"
Invoke-RestMethod -Method 'POST' -Uri $api_url_env -Authentication Bearer -Token $token -ContentType 'application/json' -Body $body | out-null
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.