Netlify’s API is surprisingly powerful, letting you manage your entire site lifecycle, from creation to deployment and beyond, all without touching the UI.
Let’s see it in action. Imagine you’ve got a new project and you want to deploy it to Netlify. You can do this with a few simple API calls.
First, you need to create a new site. This involves POSTing to the /sites endpoint.
curl -X POST \
-H "Authorization: Bearer YOUR_NETLIFY_AUTH_TOKEN" \
-d "repo_url=https://github.com/your-username/your-repo" \
"https://api.netlify.com/api/v1/sites"
This command creates a new Netlify site linked to your GitHub repository. Netlify then automatically sets up a continuous deployment pipeline, pulling from that repo.
Once the site is created, you can trigger a new deploy. This is done by POSTing to the /deploys endpoint for your specific site ID.
curl -X POST \
-H "Authorization: Bearer YOUR_NETLIFY_AUTH_TOKEN" \
-d "site_id=YOUR_SITE_ID" \
"https://api.netlify.com/api/v1/deploys"
This tells Netlify to build and deploy the latest commit from your linked repository. You’ll get a deploy ID back, which you can then use to check the status of the deploy.
curl -H "Authorization: Bearer YOUR_NETLIFY_AUTH_TOKEN" \
"https://api.netlify.com/api/v1/sites/YOUR_SITE_ID/deploys/YOUR_DEPLOY_ID"
You can poll this endpoint until the state is ready.
This API isn’t just for deployments. You can also manage environment variables, DNS records, and even custom domains. For instance, to add an environment variable to your site:
curl -X POST \
-H "Authorization: Bearer YOUR_NETLIFY_AUTH_TOKEN" \
-d "name=MY_API_KEY" \
-d "value=supersecretkey123" \
"https://api.netlify.com/api/v1/sites/YOUR_SITE_ID/env"
This injects MY_API_KEY with the value supersecretkey123 into your site’s build environment, making it available during the build process.
The true power comes from orchestrating these calls. You can build scripts that automatically create new staging sites for every pull request, deploy them, run tests, and then tear them down. Or, you could set up a workflow where a successful build on one branch triggers a deploy to a production-like environment.
The API uses standard REST principles. You authenticate using a Personal Access Token, which you can generate in your Netlify account settings under "Applications." All requests are made to https://api.netlify.com/api/v1/. You’ll be interacting with resources like /sites, /deploys, /env, and /dns.
A common misconception is that you need to fetch site details to update them. While you can GET site information, many operations are direct POSTs or PUTs to specific resource endpoints. For example, to update an existing environment variable, you’d POST to the /env endpoint with the name and new value. Netlify handles the update if the name already exists.
The next step is often managing Netlify Functions programmatically, which allows you to extend your site’s backend logic.