Created
June 28, 2012 15:24
-
-
Save sugarknowledge/3011983 to your computer and use it in GitHub Desktop.
PHP Example using NuSOAP with the v4 SOAP API to login and retrieve a session id
This file contains 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 | |
( | |
[id] => 9uukc92a6lb9v620reqv34mmg1 | |
[module_name] => Users | |
[name_value_list] => Array | |
( | |
[0] => Array | |
( | |
[name] => user_id | |
[value] => 1 | |
) | |
[1] => Array | |
( | |
[name] => user_name | |
[value] => admin | |
) | |
[2] => Array | |
( | |
[name] => user_language | |
[value] => en_us | |
) | |
[3] => Array | |
( | |
[name] => user_currency_id | |
[value] => -99 | |
) | |
[4] => Array | |
( | |
[name] => user_is_admin | |
[value] => 1 | |
) | |
[5] => Array | |
( | |
[name] => user_default_team_id | |
[value] => 1 | |
) | |
[6] => Array | |
( | |
[name] => user_default_dateformat | |
[value] => m/d/Y | |
) | |
[7] => Array | |
( | |
[name] => user_default_timeformat | |
[value] => h:ia | |
) | |
[8] => Array | |
( | |
[name] => user_number_seperator | |
[value] => , | |
) | |
[9] => Array | |
( | |
[name] => user_decimal_seperator | |
[value] => . | |
) | |
[10] => Array | |
( | |
[name] => mobile_max_list_entries | |
[value] => 10 | |
) | |
[11] => Array | |
( | |
[name] => mobile_max_subpanel_entries | |
[value] => 3 | |
) | |
[12] => Array | |
( | |
[name] => user_currency_name | |
[value] => US Dollars | |
) | |
) | |
) |
This file contains 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 | |
$username = "admin"; | |
$password = "password"; | |
$url = "http://{site_url}/service/v4/soap.php?wsdl"; | |
//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']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment