How to redeploy via API?

My project is linked to a (BitBucket) Git repository for continuous deployment.

The build command includes an npm script that fetches 301/302 redirects from our CMS, and writes them to the netlify.toml file.

When redirects are updated in the CMS, I therefore want to re-trigger the latest deployment so that that the netlify.toml file is regenerated and deployed.

I’m not sure how I can do this via the API. If I simply POST to https://api.netlify.com/api/v1/sites/{site_id}/deploys, without providing any request body, a build is created, but it doesn’t progress from status “New”.

It seems that I need to give it a list of files to deploy, but the only changed file is netlify.toml, which is generated dynamically at build.

I guess I just want to mimic the behaviour of the “Trigger deploy” button in the Netlify admin console: how can I do this via the API? What API route should I call, and what combination of params should I provide it?

I’ve routed this request to our helpdesk, we’ll follow up via email.

Thanks, but I think this can be closed, actually - I’ve realised that Netlify Build Hooks ( Build hooks | Netlify Docs ) will do exactly what I want: trigger a build + deploy of a specific site without needing to pass it any updated content or configuration.

I’d be curious to see if the same is possible via API, but for now, my issue is resolved.

1 Like

Thanks for letting us know!