---
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-07-09T04:30:43.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

News & Announcements June 25, 2026

[

### Netlify Functions, designed for Agent Experience

](/blog/netlify-functions-designed-for-agent-experience)

-   ![Profile picture of Eduardo Bouças](/_astro/52958f21e8450baf6d8e60302341a984e220c0cd-512x512_13VDlu.webp)
    
    Eduardo Bouças
    

News & Announcements June 24, 2026

[

### How we measure Netlify’s Agent Experience

](/blog/how-we-measure-netlify-agent-experience)

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

Guides & Tutorials May 15, 2026

[

### How to build a real-time AI chatbot in minutes with Netlify Agent Runners (no backend)

](/blog/how-to-build-a-real-time-ai-chatbot-in-minutes-with-netlify-agent-runners-no-backend)

-   ![Profile picture of Nahrin Jalal](/_astro/f0e7c8f227a03fe58340c99ef5439d5a896c0733-272x272_Z23kDpD.webp)
    
    Nahrin Jalal
    

![](/_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/)