# Remove Contacts from a 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/).

## Operation overview

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

**This endpoint allows you to remove contacts from a given list.**

The contacts will not be deleted. Only their list membership will be changed.

## Operation details

### Authentication

API Key

### Headers

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

### Path parameters

```json
[{"name":"id","in":"path","required":true,"description":"The ID of the list on which you want to perform the operation.","schema":{"type":"string"}}]
```

### Query string

```json
[{"name":"contact_ids","in":"query","description":"Comma separated list of contact IDs that you want to remove from the specified contacts list.","required":true,"schema":{"type":"string","minLength":1}}]
```

### Responses

```json
[{"responseCode":"202","schema":{"description":"","content":{"application/json":{"schema":{"type":"object","description":"The removal is accepted and processing.","properties":{"job_id":{"type":"string","description":"job_id of the async job"}}}}}}},{"responseCode":"400","schema":{"description":"","content":{"application/json":{"schema":{"title":"error","type":"object","required":["message"],"refName":"Error","modelName":"Error","properties":{"message":{"type":"string"},"field":{"type":"string"},"error_id":{"type":"string"},"parameter":{"type":"string"}}}}}}},{"responseCode":"404","schema":{"description":"","content":{"application/json":{"schema":{"description":"The specified list ID does not exist or one or more contact IDs do not exist."}}}}}]
```

Remove Contacts from a List

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

const id = "id";
const queryParams = { contact_ids: "contact_ids" };

const request = {
  url: `/v3/marketing/lists/${id}/contacts`,
  method: "DELETE",
  qs: queryParams,
};

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"))

id = "id"
params = {"contact_ids": "contact_ids"}

response = sg.client.marketing.lists._(id).contacts.delete(query_params=params)

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 id = "id";
        var queryParams = @"{'contact_ids': 'contact_ids'}";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.DELETE,
            urlPath: $"marketing/lists/{id}/contacts",
            queryParams: queryParams);

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

```java
import com.sendgrid.*;
import java.io.IOException;

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.DELETE);
            request.setEndpoint("/marketing/lists/id/contacts");
            request.addQueryParam("contact_ids", "contact_ids");
            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/id/contacts", host)
	request.Method = "DELETE"
	queryParams := make(map[string]string)
	queryParams["contact_ids"] = "contact_ids"
	request.QueryParams = queryParams
	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);
$query_params = json_decode('{
    "contact_ids": "contact_ids"
}');
$id = "id";

try {
    $response = $sg->client
        ->marketing()
        ->lists()
        ->_($id)
        ->contacts()
        ->delete(null, $query_params);
    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'])
id = "id"
params = JSON.parse('{
  "contact_ids": "contact_ids"
}')

response = sg.client.marketing.lists._(id).contacts.delete(query_params: params)
puts response.status_code
puts response.headers
puts response.body
```

```bash
curl -X DELETE "https://api.sendgrid.com/v3/marketing/lists/id/contacts?contact_ids=contact_ids" \
--header "Authorization: Bearer $SENDGRID_API_KEY"
```
