Thanks for the question, here is an example…
Add a input to your web-form to capture the note data:
<textarea name="note" cols="4" rows="4"></textarea>
Post that data into a new note by making two changes to your script:
1) Remove the note value from the default array
// Remember the note activity text
$noteText = $dataArray['note'];
// Remove it from the data, we will add it later
unset($dataArray['note']);
2) Add a new section to post the note to Solve in a separate transaction
// Adding note activity
// Connection to the host
$fp = fsockopen("ssl://" . HOST, 443, $errno, $errstr, TIMEOUT);
if (!$fp) {
die('Cannot connect to Solve360 host');
} else {
// Preparing data for the note
$noteText = str_replace("\n", "<br/>", $noteText);
// Forming new data
$dataArray = array(
'parent' => $newContactId,
'data' => array (
'details' => $noteText
)
);
$data = http_build_query($dataArray);
// Prepare request body
$request = "POST /contacts/note HTTP/1.1\r\n";
$request .= "Host: ".HOST."\r\n";
// Authorization header
$request .= "Authorization: Basic ".base64_encode(USER.":".TOKEN)."\r\n";
// We inform the server that we're sending data in form encoded format
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
// We inform the server theat we are waiting for xml formatted data in response
$request .= "Accept: application/xml\r\n";
$request .= "Content-Length: ".strlen($data)."\r\n";
$request .= "Connection: close\r\n\r\n";
$request .= $data;
// Send request to the host
fwrite($fp, $request);
stream_set_timeout($fp, TIMEOUT);
$info = stream_get_meta_data($fp);
// Read the response
$response = '';
while (!feof($fp) && !$info['timed_out']) {
$newLine = stream_get_line($fp, 1024, "\n");
$response .= $newLine;
if (trim($newLine) === '0') {
break;
}
$info = stream_get_meta_data($fp);
}
fclose($fp);
// Get xml from response
$results = explode('<?xml', $response);
if (!empty($results[1])) {
$xml = simplexml_load_string("<?xml ".$results['1']);
// Mail the user with the result information
mail(USER, 'Note was added to "' . $newContactName . '" contact in Solve360',
'Note with id ' . (string) $xml->id . ' was added to the contact '
. ' with id ' . $newContactId);
} else {
// Something went wrong and we haven't got xml in the response
die('System error');
}
if (isset($xml->errors)) {
mail(USER, 'Error while adding note to a contact Solve360', 'Error: ' . $xml->errors->asXml());
die ($xml->errors->asXml());
}
}
// End of adding note activity
To make this easier to follow ‘in context” we’ll update our API docs to include this example.