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/
https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/environments/%7Benvironment_uuid%7D/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?
nvm I found the same info in network tabfor 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": {}}`
@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 environmentif (!$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}
It looks like you're new here. Sign in or register to get started.