# Create List

## API Overview

Lists are static collections of Marketing Campaigns contacts. This API allows you to interact with the list objects themselves. To add contacts to a list, you must use the [Contacts API](/docs/sendgrid/api-reference/contacts/add-or-update-a-contact).

You can also manage your lists using the [Contacts menu in the Marketing Campaigns UI](https://mc.sendgrid.com/contacts). For more information about lists and best practices for building them, see ["Building your Contact List"](/docs/sendgrid/ui/managing-contacts/building-your-contact-list/).

> \[!NOTE]
>
> You can create a maximum of 1000 lists.

## Operation overview

```json
{"path":"https://api.sendgrid.com/v3/marketing/lists","method":"post","servers":[{"url":"https://api.sendgrid.com","description":"The Twilio SendGrid v3 API"}]}
```

**This endpoint creates a new contacts list.**

Once you create a list, you can use the UI to [trigger an automation](/docs/sendgrid/ui/sending-email/getting-started-with-automation/#create-an-automation) every time you add a new contact to the list.

A link to the newly created object is in `_metadata`.

## Operation details

### Authentication

API Key

### Headers

```json
[{"in":"header","name":"Authorization","required":true,"default":"Bearer <<YOUR_API_KEY_HERE>>","schema":{"type":"string"}}]
```

### Request body

```json
{"schema":{"type":"object","required":["name"],"example":{"name":"list-name"},"properties":{"name":{"type":"string","description":"Your name for your list","minLength":1,"maxLength":100}}},"encodingType":"application/json"}
```

### Responses

```json
[{"responseCode":"201","schema":{"description":"","content":{"application/json":{"schema":{"title":"list","type":"object","refName":"List","modelName":"List","properties":{"id":{"type":"string","description":"The generated ID for your list.","minLength":36,"maxLength":36},"name":{"type":"string","description":"The name you gave your list."},"contact_count":{"type":"integer","description":"The number of contacts currently stored on the list."},"_metadata":{"title":"selfMetadata","type":"object","refName":"SelfMetadata","modelName":"SelfMetadata","properties":{"self":{"type":"string","description":"A link to this object."}}}}},"examples":{"response":{"value":{"id":"ca7a3796-e8a8-4029-9ccb-df8937940562","name":"list-name","contact_count":0,"_metadata":{"self":"https://api.sendgrid.com/v3/marketing/lists/ca7a3796-e8a8-4029-9ccb-df8937940562"}}}}}}}},{"responseCode":"400","schema":{"description":"","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"array","items":{"title":"error","type":"object","required":["message"],"refName":"Error","modelName":"Error","properties":{"message":{"type":"string"},"field":{"type":"string"},"error_id":{"type":"string"},"parameter":{"type":"string"}}}}}}}}}}]
```

Create List

```js
const client = require("@sendgrid/client");
client.setApiKey(process.env.SENDGRID_API_KEY);

const data = {
  name: "list-name",
};

const request = {
  url: `/v3/marketing/lists`,
  method: "POST",
  body: data,
};

client
  .request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(response.body);
  })
  .catch((error) => {
    console.error(error);
  });
```

```python
import os
from sendgrid import SendGridAPIClient


sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))

data = {"name": "list-name"}

response = sg.client.marketing.lists.post(request_body=data)

print(response.status_code)
print(response.body)
print(response.headers)
```

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SendGrid;

public class Program {
    public static async Task Main() {
        string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);

        var data =
            @"{
            ""name"": ""list-name""
        }";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.POST, urlPath: "marketing/lists", requestBody: data);

        Console.WriteLine(response.StatusCode);
        Console.WriteLine(response.Body.ReadAsStringAsync().Result);
        Console.WriteLine(response.Headers.ToString());
    }
}
```

```java
import com.sendgrid.*;
import java.io.IOException;
import org.json.JSONObject;
import java.util.HashMap;

public class Example {
    public static void main(String[] args) throws IOException {
        try {
            SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
            Request request = new Request();
            request.setMethod(Method.POST);
            request.setEndpoint("/marketing/lists");
            request.setBody(new JSONObject(new HashMap<String, Object>() {
                {
                    put("name", "list-name");
                }
            }).toString());
            Response response = sg.api(request);
            System.out.println(response.getStatusCode());
            System.out.println(response.getBody());
            System.out.println(response.getHeaders());
        } catch (IOException ex) {
            throw ex;
        }
    }
}
```

```go
package main

import (
	"fmt"
	"github.com/sendgrid/sendgrid-go"
	"os"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")
	host := "https://api.sendgrid.com"
	request := sendgrid.GetRequest(apiKey, "/v3/marketing/lists", host)
	request.Method = "POST"
	request.Body = []byte(`{
  "name": "list-name"
}`)
	response, err := sendgrid.API(request)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
}
```

```php
<?php
// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment next line if you're not using a dependency loader (such as Composer)
// require_once '<PATH TO>/sendgrid-php.php';

$apiKey = getenv("SENDGRID_API_KEY");
$sg = new \SendGrid($apiKey);
$request_body = json_decode('{
    "name": "list-name"
}');

try {
    $response = $sg->client
        ->marketing()
        ->lists()
        ->post($request_body);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $ex) {
    echo "Caught exception: " . $ex->getMessage();
}
```

```ruby
require 'sendgrid-ruby'
include SendGrid

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
data = JSON.parse('{
  "name": "list-name"
}')

response = sg.client.marketing.lists.post(request_body: data)
puts response.status_code
puts response.headers
puts response.body
```

```bash
curl -X POST "https://api.sendgrid.com/v3/marketing/lists" \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data '{"name": "list-name"}'
```
