×

This API allows you to add contacts within an already created list. The contacts should already exists in Campaigns or should be created using Create Contacts API.

This is a bulk API which supports maximum of 5000 contacts in one request.

POST

https://<your_api_key>:<your_api_token><subdomain>/v2/accounts/<your_sid>/lists/<listSid>/contacts

  • Replace <your_api_key> and <your_api_token> with the API key and token created by you.
  • Replace <your_sid> with your “Account sid”
  • Replace <subdomain> with the region of your account
    1. <subdomain> of Singapore cluster is @api.exotel.com
    2. <subdomain> of Mumbai cluster is @api.in.exotel.com

<your_api_key> , <your_api_token> and <your_sid> are available in the API settings page of your Exotel Dashboard

curl -X POST 'https://<your_api_key>:<your_api_token>@<subdomain>/v2/accounts/exotel8u3/lists/<list_id>/contacts' \
--header 'Content-Type: application/json' \
--data-raw '{
  "contact_references": [
    {"contact_sid":"d49b7a4781ea45dcb702825ce30494ba"},
    {"contact_sid":"68bc98cae5a24cc3b017258a73e8a809"}
  ]
}'
var unirest = require('unirest');
var accountSid = "XXXXXXXXX";
var accountToken = "YYYYYYYYY";
var authKey = "ZZZZZZZZZZ";
var encoding = Buffer.from(authKey + ':' + accountToken).toString('base64');
var req = unirest('POST', "https://<subdomain>/v2/accounts/"+accountSid+"/lists/+list_id+/contacts")
  .headers({
	  Authorization: 'Basic ' + encoding,
	  'Content-Type': 'application/json'
  })
  .send(JSON.stringify({"{   "contact_references": [     {"contact_sid":"d49b7a4781ea45dcb702825ce30494ba"},     {"contact_sid":"68bc98cae5a24cc3b017258a73e8a809"}   ] }"
))
  .end(function (res) { 
    if (res.error) throw new Error(res.error); 
    console.log(res.raw_body);
  });
<?php

$curl = curl_init();
$accountSid = "XXXXXXXXXX";
$accountToken = "YYYYYYYYYY";
$authKey = "ZZZZZZZZZZ";

$encoding = base64_encode($authKey .":". $accountToken);

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<subdomain>/v2/accounts/<account_sid>/lists/<list_id>/contacts',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{   "contact_references": [     {"contact_sid":"d49b7a4781ea45dcb702825ce30494ba"},     {"contact_sid":"68bc98cae5a24cc3b017258a73e8a809"}   ] }',
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic ".$encoding,
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
import requests
import base64 
import json
accountSid = "XXXXXXXXX"
authToken = "YYYYYYYYY"
authKey = "ZZZZZZZZZZ"

encoding = base64.b64encode(authKey + ":" + authToken)

url = "https://<subdomain>/v2/accounts/"+accountSid+"/lists/+list_id+/contacts"

payload = json.dumps({   "contact_references": [     {"contact_sid":"d49b7a4781ea45dcb702825ce30494ba"},     {"contact_sid":"68bc98cae5a24cc3b017258a73e8a809"}   ] })

headers = {
    'Authorization': "Basic " + encoding,
    'Content-Type': 'application/json'
}


response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
print(json.dumps(json.loads(response.text), indent = 4, sort_keys = True))
package main

import (
	b64 "encoding/base64"
"fmt"
"io/ioutil"
"net/http"
"strings"
)

func main() {
// Please provide accountSid, authToken from your Exotel account
	accountSid := "XXXXXXXXX"
	authToken := "YYYYYYYY"
	authKey := "ZZZZZZZZZZ"
// Encoding the accountSid and authToken, used in Authorization header
	encoding := b64.StdEncoding.EncodeToString([]byte(authKey + ":" + authToken))

	url := "https://<subdomain>/v2/accounts/" + accountSid + "/lists" + list_id + "/contacts"
	method := "POST"

	payload := strings.NewReader(`{   "contact_references": [     {"contact_sid":"d49b7a4781ea45dcb702825ce30494ba"},     {"contact_sid":"68bc98cae5a24cc3b017258a73e8a809"}   ] }`)

	client := &http.Client{}
	req, err := http.NewRequest(method, url, payload)
if err != nil {
		fmt.Println(err)
return
}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Basic "+encoding)
	res, err := client.Do(req)
if err != nil {
		fmt.Println(err)
return
}
	defer res.Body.Close()

	body, err := ioutil.ReadAll(res.Body)
if err != nil {
		fmt.Println(err)
return
}
	fmt.Println(string(body))
}
{
  "request_id":"cfa7d61f24064a399789d677ef0cc379",
  "method":"POST",
  "http_code":207,
  "metadata":{
     "failed":0,
     "total":1,
     "success":1
  },
  "response":[
     {
       "code":200,
       "error_data":null,
       "status":"success",
       "data":{
       "sid":"d49b7a4781ea45dcb702825ce30494ba",
       "date_created":"2017-12-05T14:15:51.108069088+05:30",
       "date_updated":"2017-12-05T14:15:51.108069088+05:30",
       "account_sid":"Exotel",
       "list_id":"e46c2fe202904d579ae592d108cf87a0",
       "uri":"/v2/Accounts/Exotel/contacts/d49b7a4781ea45dcb702825ce30494ba"
   },
    {
      "Sid":"68bc98cae5a24cc3b017258a73e8a809",
      "date_created":"2017-12-05T14:15:51.108069088+05:30",
      "date_updated":"2017-12-05T14:15:51.108069088+05:30",
      "account_sid":"Exotel", "list_id":"e46c2fe202904d579ae592d108cf87a0",
      "uri":"/v2/Accounts/Exotel/contacts/68bc98cae5a24cc3b017258a73e8a809"
   }
  }
  ]
}