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.txtlocal.com/create_contacts_bulk/

Sample Request

  1. <?php
  2. // Account details
  3. $apiKey = urlencode('Your apiKey');
  4. // Contact details
  5. $group_id = '123456';
  6. $contacts = array(array('number' => 447123456789, 'first_name' => 'John', 'last_name' => 'Doe'), array('number' => 447987654321, 'first_name' => 'Lucy', 'last_name' => 'Smith'));
  7.  
  8. // Prepare data for POST request
  9. $data = array('apikey' => $apiKey, 'group_id' => $group_id, 'contacts' => json_encode($contacts));
  10. // Send the POST request with cURL
  11. $ch = curl_init('https://api.txtlocal.com/create_contacts_bulk/');
  12. curl_setopt($ch, CURLOPT_POST, true);
  13. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. $response = curl_exec($ch);
  16. curl_close($ch);
  17. // Process your response here
  18. echo $response;
  19. ?>
  1. <?php
  2. // Account details
  3. $apiKey = urlencode('Your apiKey');
  4. // Contact details
  5. $group_id = '123456';
  6. $contacts = urlencode(json_encode(array(array('number' => 447123456789, 'first_name' => 'John', 'last_name' => 'Doe'), array('number' => 447987654321, 'first_name' => 'Lucy', 'last_name' => 'Smith'))));
  7.  
  8. // Prepare data for POST request
  9. $data = 'apikey=' . $apiKey . '&group_id=' . $group_id . '&contacts=' . $contacts;
  10. // Send the GET request with cURL
  11. $ch = curl_init('https://api.txtlocal.com/create_contacts_bulk/?' . $data);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13. $response = curl_exec($ch);
  14. curl_close($ch);
  15. // Process your response here
  16. echo $response;
  17. ?>
  1. <?php
  2. require('Textlocal.class.php');
  3.  
  4. $Textlocal = new Textlocal(false, false, 'your apiKey');
  5.  
  6. $group_id = 43123;
  7. $contacts = array(array('first_name', 'last_name', 'number', 'custom1', 'custom2', 'custom3'), array('first_name', 'last_name', 'number', 'custom1', 'custom2', 'custom3'));
  8.  
  9. $response = $Textlocal->createContactsBulk($numbers, $group_id);
  10. print_r($response);
  11. ?>

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. 447123456789).
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

  1. [{"number":447123456789,"first_name":"John","last_name":"Doe"},{"number":447987654321,"first_name":"Lucy","last_name":"Smith"}]

Sample Response

  1. {
  2. "APIResponse":{
  3. "success":true,
  4. "numCreated":0,
  5. "contacts":[
  6. {
  7. "number":"447123456789",
  8. "firstName":"",
  9. "lastName":"",
  10. "custom1":"",
  11. "custom2":"",
  12. "custom3":"",
  13. "groupID":"123456",
  14. "trackingLink":"abc1/def123",
  15. "id":10000000001
  16. },{
  17. "number":"447987654321",
  18. "firstName":"",
  19. "lastName":"",
  20. "custom1":"",
  21. "custom2":"",
  22. "custom3":"",
  23. "groupID":"123456",
  24. "trackingLink":"abc1/def321",
  25. "id":10000000002
  26. }
  27. ]},
  28. "group_id":123456,
  29. "num_contacts":2,
  30. "status":"success"
  31. }
  1. <response>
  2. <APIResponse>
  3. <success>1</success>
  4. <numCreated>2</numCreated>
  5. <contacts>
  6. <contact>
  7. <number>447123456789</number>
  8. <firstName></firstName>
  9. <lastName></lastName>
  10. <custom1></custom1>
  11. <custom2></custom2>
  12. <custom3></custom3>
  13. <groupID>123456</groupID>
  14. <trackingLink>abc1/def123</trackingLink>
  15. <id>10000000001</id>
  16. </contact>
  17. <contact>
  18. <number>447987654321</number>
  19. <firstName></firstName>
  20. <lastName></lastName>
  21. <custom1></custom1>
  22. <custom2></custom2>
  23. <custom3></custom3>
  24. <groupID>123456</groupID>
  25. <trackingLink>abc1/def321</trackingLink>
  26. <id>10000000002</id>
  27. </contact>
  28. </contacts>
  29. </APIResponse>
  30. <group_id>123456</group_id>
  31. <num_contacts>2</num_contacts>
  32. <status>success</status>
  33. </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