---
title: "Create sites programmatically with the Netlify API"
description: "Learn how to create new sites programmatically using the Netlify API, in a single command!"
source: "https://www.netlify.com/blog/create-sites-programmatically-with-the-netlify-api/"
last_updated: "2026-08-05T07:23:33.000Z"
---
There’s a few different ways to create a site on Netlify. You can do so by clicking a few buttons in the UI, drag and drop a folder on [Netlify Drop](https://app.netlify.com/drop), or running a few commands in the [CLI](https://cli.netlify.com/). But there’s one more way; you can also create new sites programmatically using the Netlify API, in a single command!

First, you need to start by installing and importing the `netlify` package.

To install it, run `npm install netlify` or `yarn add netlify`. Then, import it with `import NetlifyAPI from "netlify"`.

Once this is done, you’ll need to instantiate a new NetlifyAPI object and pass it a Netlify token to be able to authenticate. To find your Netlify token, navigate to your user settings page in the Netlify UI, click on the “[Applications](https://app.netlify.com/user/applications)” tab and under the “Personal access tokens” settings, generate a new access token.

```
const api = new NetlifyAPI(NETLIFY_TOKEN);
```

Once this is done, you can use the `createSite` method, passing it an account slug and body containing information about the repository you’d like to use and the name of your new site.

```
const site = await api.createSite({  account_slug: "my-awesome-team" // This should be the team you'd like your site to be under. If not specified, this will use your default team.  body: {    name: "my-new-awesome-site",    repo: {      provider: "github", // or "gitlab", "bitbucket"      repo: "username/repository",      private: false,      branch: "main",    },  }});
```

The full code sample would look like this:

```
import NetlifyAPI from "netlify";
const api = new NetlifyAPI(NETLIFY_TOKEN);
const site = await api.createSite({  account_slug: "my-awesome-team"  body: {    name: "my-new-awesome-site",    repo: {      provider: "github",      repo: "username/repository",      private: true,      branch: "main",    },  }});
```

That’s it! You can use this code to create your own “Deploy to Netlify” button, or in a GitHub action to create a site automatically when you create a new repo; anything you can think of!

If you end up building anything fun, let us know!

### Share

-   [X (fka Twitter)](https://twitter.com/intent/tweet?text=Create sites programmatically with the Netlify API&url=https://www.netlify.com/blog/create-sites-programmatically-with-the-netlify-api/)
-   [LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.netlify.com%2Fblog%2Fcreate-sites-programmatically-with-the-netlify-api%2F)
-   [Facebook](https://www.facebook.com/sharer.php?u=https://www.netlify.com/blog/create-sites-programmatically-with-the-netlify-api/)
-   [Bluesky](https://bsky.app/intent/compose?text=Create sites programmatically with the Netlify API+https://www.netlify.com/blog/create-sites-programmatically-with-the-netlify-api/)

* * *

### Tags

-   [Netlify API](/blog/tags/netlify-api/)

## Keep reading

![](/images/blog-fallback-thumbnail.svg)

Guides & Tutorials September 24, 2020

[

### How to deploy a simple site using Postman and the Netlify API

](/blog/2020/09/24/how-to-deploy-a-simple-site-using-postman-and-the-netlify-api/)

-   ![Profile picture of Jen Kagan](/_astro/09dc35780e7ca2a59f0cf542b88d5d6867a7f102-80x80_Z1qlpat.webp)
    
    Jen Kagan
    

![](/images/blog-fallback-thumbnail.svg)

Guides & Tutorials December 1, 2021

[

### Publish your site assets with the Netlify CLI

](/blog/2021/12/01/publish-your-site-assets-with-the-netlify-cli/)

-   ![Profile picture of Phil Hawksworth](/_astro/9cfe2bbe94bcb555ce3ac7683ac7905ad3fd32b1-400x400_Z18H6R1.webp)
    
    Phil Hawksworth
    

## Recent posts

Opinions & Insights July 28, 2026

[

### Open Weights and the 2nd World

](/blog/open-weights-and-the-2nd-world)

-   ![Profile picture of Mathias Biilmann](/_astro/f193d4707a6391d843d5aaa73338b5a5971ec5cc-960x960_1Yylqm.webp)
    
    Mathias Biilmann
    

Tools & Services July 28, 2026

[

### MCP goes stateless and extensible

](/blog/mcp-goes-stateless-and-extensible)

-   ![Profile picture of Sean Roberts](/_astro/bbf2243f8171dbddd80ab2103622106cef84d125-512x512_Z1d2LKE.webp)
    
    Sean Roberts
    

News & Announcements July 28, 2026

[

### New Netlify projects are now private by default

](/blog/new-netlify-projects-are-now-private-by-default)

-   ![Profile picture of Taylor Barnett-Torabi](/_astro/cf4624da8c1286738397b6fecb53bad504df140b-400x400_ZsvK0s.webp)
    
    Taylor Barnett-Torabi
    

![](/_astro/3f255b372fa958df35802666ee33b4609b2d71bd-1200x1586_1VtE2D.webp)

### How do the best dev and marketing teams work together?

[Access the report](https://www.netlify.com/reports/2024-leadership-trend-report/access/)