Add existing contacts to a list

Code Examples

You can use as reference the code below to implement this call in your preferred language.
Check all our official API clients here

const SibApiV3Sdk = require('sib-api-v3-sdk');
let defaultClient = SibApiV3Sdk.ApiClient.instance;

let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'YOUR API KEY';

let apiInstance = new SibApiV3Sdk.ContactsApi();

let listId = 1;

let contactEmails = new SibApiV3Sdk.AddContactToList();

contactEmails.emails = ["[email protected]"];

apiInstance.addContactToList(listId, contactEmails).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
  console.error(error);
});
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API KEY');

$apiInstance = new SendinBlue\Client\Api\ContactsApi(
    new GuzzleHttp\Client(),
    $config
);
$listId = 1;
$contactIdentifiers = new \SendinBlue\Client\Model\AddContactToList();
$contactIdentifiers['emails'] = array('[email protected]');

try {
    $result = $apiInstance->addContactToList($listId, $contactIdentifiers);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ContactsApi->addContactToList: ', $e->getMessage(), PHP_EOL;
}
?>
from __future__ import print_function
import time
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint

configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR API KEY'

api_instance = sib_api_v3_sdk.ListsApi(sib_api_v3_sdk.ApiClient(configuration))
list_id = 2
contact_emails = sib_api_v3_sdk.AddContactToList()
contact_emails.emails = ['[email protected]']

try:
    api_response = api_instance.add_contact_to_list(list_id, contact_emails)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling ListsApi->add_contact_to_list: %s\n" % e)
const SibApiV3Sdk = require('sib-api-v3-typescript');
 
let apiInstance = new SibApiV3Sdk.ContactsApi()

let apiKey = apiInstance.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';

let listId = 1;

let contactEmails = new SibApiV3Sdk.AddContactToList(); 

contactEmails.emails = ["[email protected]"];

apiInstance.addContactToList(listId, contactEmails).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
  console.error(error);
});
package sibApi;

import sendinblue.ApiClient;
import sendinblue.Configuration;
import sendinblue.auth.ApiKeyAuth;
import sibModel.*;
import java.util.*;
import java.util.List;

public class Program {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        // Configure API key authorization: api-key
        ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("api-key");
        apiKey.setApiKey("YOUR API KEY");

        try {
            ContactsApi api = new ContactsApi();
            Long listId = 2l;
            List<String> emails = new ArrayList<String>();
            emails.add("[email protected]");
            AddContactToList contactEmails = new AddContactToList();
            contactEmails.setEmails(emails);
            PostContactInfo response = api.addContactToList(listId, contactEmails);
            System.out.println(response.toString());
        } catch (Exception e) {
            System.out.println("Exception occurred:- " + e.getMessage());
        }
    }
}
using sib_api_v3_sdk.Api;
using sib_api_v3_sdk.Client;
using sib_api_v3_sdk.Model;
using System;
using System.Diagnostics;
using System.Collections.Generic;

namespace Sendinblue
{
    class Program
    {
        static void Main(string[] args)
        {
            Configuration.Default.ApiKey.Add("api-key", "YOUR API KEY");

            var apiInstance = new ContactsApi();
            long? listId = 2;
            List<string> emails = new List<string>();
            emails.Add("[email protected]");
            try
            {
                var contactEmails = new AddContactToList(emails);
                PostContactInfo result = apiInstance.AddContactToList(listId, contactEmails);
                Debug.WriteLine(result.ToJson());
                Console.WriteLine(result.ToJson());
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }
    }
}
package main
import (
	"fmt"
	"context"
    sib_api_v3_sdk "./lib"
)

func main() {
	var ctx context.Context
	var cli = sib_api_v3_sdk.APIClient{
		cfg: sib_api_v3_sdk.NewConfiguration(),
	}
	//Configure API key authorization: api-key
	cli.cfg.AddDefaultHeader("api-key", "YOUR_API_KEY")

	sib := sib_api_v3_sdk.NewAPIClient(cli.cfg)
	listId := int64(2)
	body := AddContactToList{
		Emails: []string{
			"[email protected]",
		},
	}
	obj, resp, err := sib.ContactsApi.AddContactToList(ctx, body, listId)
    if err!=nil{
        fmt.Println("Error in ContactsApi->GetContactsFromList ",err.Error())
        return
    }
	fmt.Println( "GetContactsFromList response:",resp,"GetContactsFromList object:",obj)
	return 
}
# load the gem
require 'sib-api-v3-sdk'
# setup authorization
SibApiV3Sdk.configure do |config|
  # Configure API key authorization: api-key
  config.api_key['api-key'] = 'YOUR API KEY'
end

api_instance = SibApiV3Sdk::ContactsApi.new

list_id = 789 # Integer | Id of the list

contact_emails = SibApiV3Sdk::AddContactToList.new # AddContactToList | Emails addresses OR IDs of the contacts

contact_emails = {
  'emails' => ['[email protected]']
}

begin
  #Add existing contacts to a list
  result = api_instance.add_contact_to_list(list_id, contact_emails)
  p result
rescue SibApiV3Sdk::ApiError => e
  puts "Exception when calling ContactsApi->add_contact_to_list: #{e}"
end
Language
Authorization
Header
Click Try It! to start a request and see the response here!