Delete pipeline via API fails with 403 Forbidden again

Getting 403 when deleting environment via API

*Describe your question in as much detail as possible:

  • What are you seeing, and how does it differ from what you expect to see?*
    • I’m getting 403 when deleting the environment via API. I have tried a few ways to pass to the token. Also different tokens - job token and personal token with all privileges - api, sudo, admin, etc. Also, I added the project to Limit access to this project in CI/CD settings.
curl -X DELETE -H "PRIVATE-TOKEN: [MASKED]" 'https://XXXX.net/api/v4/projects/YYYY%2Fecom2-shop/environments/9813'
{"message":"403 Forbidden"}

curl -X DELETE -F private_token="[MASKED]" 'https://XXXX.net/api/v4/projects/YYYY%2Fecom2-shop/environments/9813'
{"message":"403 Forbidden"}

curl -X DELETE -H "Authorization: Bearer [MASKED]" 'https://XXXX.net/api/v4/projects/YYYY%2Fecom2-shop/environments/9813'
{"message":"403 Forbidden"}

curl -X DELETE 'https://XXXX.net/api/v4/projects/YYYY%2Fecom2-shop/environments/9813?job_token=[MASKED]'
{"message":"403 Forbidden"}
  • Consider including screenshots, error messages, and/or other helpful visuals
    • gitlab-workhorse:
{"content_type":"application/json","correlation_id":"blahblahblah","duration_ms":101,"host":"XXXX.net","level":"info","method":"DELETE","msg":"access","proto":"HTTP/1.1","referrer":"","remote_addr":"127.0.0.1:0","remote_ip":"127.0.0.1","route":"^/api/","status":403,"system":"http","time":"2023-10-02T19:29:19+02:00","ttfb_ms":101,"uri":"/api/v4/projects/YYYY%2Fecom2-shop/environments/9813?job_token=[FILTERED]","user_agent":"curl/8.3.0","written_bytes":27}

Well I found the problem. 403 = Environment is not stopped. Even if env is just available it can’t be deleted. So you have to stop it first via POST …ID/stop. And then you can delete it.