Locking current production deploy

I’ve been trying to emulate the UI functionality of locking the current production deploy auto publishing via the api.

I’ve successfully changed several settings using the patch updateSite endpoint

For example, toggling the stop_builds setting works:

data = {
        "build_settings": {
            "stop_builds": true,

However this has no effect for a particular site_id

data = {
        "published_deploy": {
            "locked": true,

Is this the right endpoint to be using to replicate the UI function?

The endpoint is:

POST /deploys/<id>/lock

In the UI, the “lock to stop auto publishing” is set at the site level, and has the impact of locking to whichever deploy is published (even if the published deploy is not the most recent).

Clicking here:

Gives this popup:

In the api, the lockDeploy endpoint requries me to provide a specific deploy_id.

So- I’m assuming there is no endpoint that “locks the published deploy” for a site_id.

Which leaves me trying to figure out how to retrieve a specific site_id’s published deploy id to feed into lockDeploy.

Is it listSiteDeploys (https://api.netlify.com/api/v1/sites/{site_id}/deploys)?

I’m looking at the documentation - and it isn’t jumping out at me from the sample response - how to retrieve the published deploy_id from that endpoint.

You can get the deploy ID from the site info: Netlify API documentation which has a published_deploy object.

Thanks - now got it working, along with a few other endpoints.

The one I could never figure out though was toggling on analytics. I tried a few variations from the patch updateSite endpoint - but nothing seemed to stick.

I think it’s a POST to /sites/<site-id>/analytics

Am I just missing it in the docs, or is that an undocumented endpoint?

Is there a payload to turn on/off?

You can inspect our UI: [Support Guide] Understanding and using Netlify’s API - Support / Support Guides - Netlify Support Forums to find out API calls. And no, there’s no payload that I found when inspecting it myself.