Created
July 3, 2012 21:19
-
-
Save sugarknowledge/3043242 to your computer and use it in GitHub Desktop.
PHP Example using NuSOAP with the v4 SOAP API to retrieve account records with get_entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array | |
| ( | |
| [entry_list] => Array | |
| ( | |
| [0] => Array | |
| ( | |
| [id] => 20328809-9d0a-56fc-0e7c-4f7cb6eb1c83 | |
| [module_name] => Accounts | |
| [name_value_list] => Array | |
| ( | |
| [0] => Array | |
| ( | |
| [name] => name | |
| [value] => Jungle Systems Inc | |
| ) | |
| [1] => Array | |
| ( | |
| [name] => billing_address_state | |
| [value] => NY | |
| ) | |
| [2] => Array | |
| ( | |
| [name] => billing_address_country | |
| [value] => USA | |
| ) | |
| ) | |
| ) | |
| [1] => Array | |
| ( | |
| [id] => 328b22a6-d784-66d9-0295-4f7cb59e8cbb | |
| [module_name] => Accounts | |
| [name_value_list] => Array | |
| ( | |
| [0] => Array | |
| ( | |
| [name] => name | |
| [value] => Riviera Hotels | |
| ) | |
| [1] => Array | |
| ( | |
| [name] => billing_address_state | |
| [value] => CA | |
| ) | |
| [2] => Array | |
| ( | |
| [name] => billing_address_country | |
| [value] => USA | |
| ) | |
| ) | |
| ) | |
| ) | |
| [relationship_list] => Array | |
| ( | |
| ) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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']; | |
| //retrieve records ------------------------------------------------------------------------------- | |
| $get_entries_parameters = array( | |
| //session id | |
| 'session' => $session_id, | |
| //The name of the module from which to retrieve records | |
| 'module_name' => 'Accounts', | |
| //An array of SugarBean IDs | |
| 'ids' => array( | |
| '20328809-9d0a-56fc-0e7c-4f7cb6eb1c83', | |
| '328b22a6-d784-66d9-0295-4f7cb59e8cbb', | |
| ), | |
| //Optional. The list of fields to be returned in the results | |
| 'select_fields' => array( | |
| 'name', | |
| 'billing_address_state', | |
| 'billing_address_country' | |
| ), | |
| //A list of link names and the fields to be returned for each link name | |
| 'link_name_to_fields_array' => array( | |
| ), | |
| ); | |
| $get_entries_result = $client->call('get_entries', $get_entries_parameters); | |
| echo '<pre>'; | |
| print_r($get_entries_result); | |
| echo '</pre>'; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment