Add new contact custom field.
| Description: | Add a new contact custom field, just like you would on the Custom Fields page of the admin section. | ||||||||||||||||||||||
| HTTP method: | POST |
||||||||||||||||||||||
| Supported output formats: | xml, json, serialize |
||||||||||||||||||||||
| Requires authentication: | true |
||||||||||||||||||||||
| Parameters: |
* indicates requirement. Underlined params include in URL, otherwise as part of the post body. POST data must be formatted as
Content-Type: application/x-www-form-urlencoded. We don't accept any other input formats like JSON.
|
||||||||||||||||||||||
| Example response: |
|
PHP Example
This is an example of using the contact_sync call with PHP. You can replicate the same idea in virtually any other programming language. The example shown is using serialize as the output format. You can change that to XML or JSON if you would like.
<?php
// By default, this sample code is designed to get the result
$url = 'https://api.t2connect.com/v1/';
// here we define the data we are posting in order to perform an update
$data = array(
'account' => 'YOUR_URL',
// replace this with your API Key
'api_key' => 'YOUR_API_KEY',
// this is the action that adds a contact
// this is the action that adds a list
'api_action' => 'list_field_add',
// define the type of output you wish to get back
// possible values:
// - 'xml' : you have to write your own XML parser
// - 'json' : data is returned in JSON format and can be decoded with
// json_decode() function (included in PHP since 5.2.0)
// - 'serialize' : data is returned in a serialized format and can be decoded with
// a native unserialize() function
'api_output' => 'serialize',
);
// here we define the data we are posting in order to perform an update
$data= array(
'title' => 'Field 1', // internal field name
'type' => 1, // 1 = Text Field, 2 = Text Box, 3 = Checkbox, 4 = Radio, 5 = Dropdown, 6 = Hidden field, 7 = List Box, 9 = Date
'req' => 0, // required? 1 or 0
'perstag' => '', // unique tag used as a placeholder for dynamic content
'p[0]' => 0, // for use in lists. use 0 for All lists
//'p[2]' => 2, // more lists?
'options[label]' => 'value',
//'options[label]' => 'value2', // more options?
);
//open connection
$ch = curl_init($url);
$json_data = json_encode($data);
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment if you get no gateway response and are using HTTPS
$response = (string)curl_exec($ch); // execute curl post and store results in $response
//close connection
curl_close($ch);
$result = unserialize($response);
// Result info that is always returned
echo 'Result: ' . ( $result['result_code'] ? 'SUCCESS' : 'FAILED' ) . '<br />';
echo 'Message: ' . $result['result_message'] . '<br />';
// The entire result printed out
echo 'The entire result printed out:<br />';
echo '<pre>';
print_r($result);
echo '</pre>';
// Raw response printed out
echo 'Raw response printed out:<br />';
echo '<pre>';
print_r($response);
echo '</pre>';
?>