Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

POST method docs to update environment seems incomplete?

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"?

1 answer

1 accepted

0 votes
Answer accepted

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 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": {}}`

Like Thomas Totter likes this

@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
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events