Skip to content

Instantly share code, notes, and snippets.

@sugarknowledge
Created November 20, 2012 18:41
Show Gist options
  • Save sugarknowledge/4120027 to your computer and use it in GitHub Desktop.
Save sugarknowledge/4120027 to your computer and use it in GitHub Desktop.
PHP Example using NuSOAP with the v4 SOAP API to create a note with an attachement
//set_entry result
Array
(
[id] => 59a33435-7c6a-2d97-e61b-50abcc5d2644
)
//set_note_attachment result
Array
(
[id] => 59a33435-7c6a-2d97-e61b-50abcc5d2644
)
<?php
$url = "http://{site_url}/service/v4/soap.php?wsdl";
$username = "admin";
$password = "password";
//require NuSOAP
require_once("./nusoap/lib/nusoap.php");
//retrieve WSDL
$client = new nusoap_client($url, 'wsdl');
//display errors
$err = $client->getError();
if ($err)
{
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
//login -------------------------------------------------------
$login_parameters = array(
'user_auth' => array(
'user_name' => $username,
'password' => md5($password),
'version' => '1'
),
'application_name' => 'SoapTest',
'name_value_list' => array(
),
);
$login_result = $client->call('login', $login_parameters);
/*
echo '<pre>';
print_r($login_result);
echo '</pre>';
*/
//get session id
$session_id = $login_result['id'];
//create note -----------------------------------------------------------------------------------
$set_entry_parameters = array(
//session id
"session" => $session_id,
//The name of the module
"module_name" => "Notes",
//Record attributes
"name_value_list" => array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
array("name" => "name", "value" => "Example Note"),
),
);
$set_entry_result = $client->call("set_entry", $set_entry_parameters);
echo "<pre>";
print_r($set_entry_result);
echo "</pre>";
$note_id = $set_entry_result['id'];
//create note attachment -----------------------------------------------------------------------------------
$contents = file_get_contents ("/path/to/example_file.php");
$set_note_attachment_parameters = array(
//session id
"session" => $session_id,
//The attachment details
"note" => array(
//The ID of the note containing the attachment.
'id' => $note_id,
//The file name of the attachment.
'filename' => 'example_file.php',
//The binary contents of the file.
'file' => base64_encode($contents),
),
);
$set_note_attachment_result = $client->call("set_note_attachment", $set_note_attachment_parameters);
echo "<pre>";
print_r($set_note_attachment_result);
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment