Textlocal Logo

API Documentation

Bulk Create Contacts

This command can be used to insert up to 1500 new numbers into your Textlocal contact groups and will allow you to insert extra fields such as the contact's name.

Resource URL

https://api.textlocal.in/create_contacts_bulk/

Sample Request

<?php
	// Account details
	$apiKey = urlencode('Your apiKey');
	
	// Contact details
	$group_id = '123456';
	$contacts = array(array('number' => 918123456789, 'first_name' => 'John', 'last_name' => 'Doe'), array('number' => 918987654321, 'first_name' => 'Lucy', 'last_name' => 'Smith'));

	// Prepare data for POST request
	$data = array('apikey' => $apiKey, 'group_id' => $group_id, 'contacts' => json_encode($contacts));
 
	// Send the POST request with cURL
	$ch = curl_init('https://api.textlocal.in/create_contacts_bulk/');
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
	
	// Process your response here
	echo $response;
?>
<?php
	// Account details
	$apiKey = urlencode('Your apiKey');
	
	// Contact details
	$group_id = '123456';
	$contacts = urlencode(json_encode(array(array('number' => 918123456789, 'first_name' => 'John', 'last_name' => 'Doe'), array('number' => 918987654321, 'first_name' => 'Lucy', 'last_name' => 'Smith'))));

	// Prepare data for POST request
	$data = 'apikey=' . $apiKey . '&group_id=' . $group_id . '&contacts=' . $contacts;
 
	// Send the GET request with cURL
	$ch = curl_init('https://api.textlocal.in/create_contacts_bulk/?' . $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
	
	// Process your response here
	echo $response;
?>
<?php
	require('Textlocal.class.php');

	$Textlocal = new Textlocal(false, false, 'your apiKey');

	$group_id = 43123;
	$contacts = array(array('first_name', 'last_name', 'number', 'custom1', 'custom2', 'custom3'), array('first_name', 'last_name', 'number', 'custom1', 'custom2', 'custom3'));

	$response = $Textlocal->createContactsBulk($numbers, $group_id);
	print_r($response);
?>

Parameters

group_id ID of the group. Can either be found within Messenger (in the "Reports" - "Advanced Reports" - "List of Group ID's" section) or by running the get_groups command. Additionally group 5 contains "contacts"
contactsJSON Object
number The mobile number in international format (i.e. 918123456789).
Optional Parameters
first_name The first name to be assigned to this contact.
last_name The last name to be assigned to this contact.
custom1 A custom1 to be assigned to this contact.
custom2 A custom2 to be assigned to this contact.
custom3 A custom3 to be assigned to this contact.
Login Parameters (Additional Information)
apiKey You can create these in your Messenger Control Panel (click here) for each application, and limit the usage of them by host IP Address.

Warning: It is recommended to send this request via POST, as there is a limited number of characters that can be sent via GET (approx. 8000) and a large contacts JSON object may exceed this.

Sample JSON Object

[{"number":918123456789,"first_name":"John","last_name":"Doe"},{"number":918123456788,"first_name":"Pavan","last_name":"Kumar"}]

Sample Response

{
	"APIResponse":{
	"success":true,
	"numCreated":0,
	"contacts":[
		{
		"number":"918123456789",
		"firstName":"",
		"lastName":"",
		"custom1":"",
		"custom2":"",
		"custom3":"",
		"groupID":"123456",
		"trackingLink":"abc1/def123",
		"id":10000000001
	},{
		"number":"918987654321",
		"firstName":"",
		"lastName":"",
		"custom1":"",
		"custom2":"",
		"custom3":"",
		"groupID":"123456",
		"trackingLink":"abc1/def321",
		"id":10000000002
		}
	]},
	"group_id":123456,
	"num_contacts":2,
	"status":"success"
}
<response>
	<APIResponse>
		<success>1</success>
		<numCreated>2</numCreated>
		<contacts>
			<contact>
				<number>918123456789</number>
				<firstName></firstName>
				<lastName></lastName>
				<custom1></custom1>
				<custom2></custom2>
				<custom3></custom3>
				<groupID>123456</groupID>
				<trackingLink>abc1/def123</trackingLink>
				<id>10000000001</id>
			</contact>
			<contact>
				<number>918987654321</number>
				<firstName></firstName>
				<lastName></lastName>
				<custom1></custom1>
				<custom2></custom2>
				<custom3></custom3>
				<groupID>123456</groupID>
				<trackingLink>abc1/def321</trackingLink>
				<id>10000000002</id>
			</contact>
		</contacts>
	</APIResponse>
	<group_id>123456</group_id>
	<num_contacts>2</num_contacts>
	<status>success</status>
</response>

Note: This request returns a Link Tracking parameter which can be used with a Survey Link to send out pre-created Survey's via our API.

Errors

Error Codes
10 Invalid group ID.
15 Invalid JSON string.
25 No group ID specified.
33 You have supplied too many numbers