Omniture Web Services
April 12th, 2009
| Tags: PHP, soap, web service
I’ve been working with the Omniture Web Services API lately, it puzzles me why all the provided PHP sample code uses NuSOAP.
PHP has a native SoapClient, as far as I can see there is no need to use the huge NuSOAP library.
The only challenge is how to make the authentication with the Omniture Web services work.
Inspired by the samples in the Omniture Web Services API documentation, I’ve put together a tiny extension to the PHP SoapClient that takes care of that.
You can get a copy here : OmnitureSoapClient.php
Some simple sample code to illustrate usage :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | <html> <body> <?php require_once 'OmnitureSoapClient.php'; $options=array('exceptions'=>false); $username="username:company"; $secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $wsdl="OmnitureAdminServices.wsdl"; $client = new OmnitureSoapClient($wsdl,$username,$secret,$options); $result = $client->__soapCall('Company.GetTokenUsage',array()); if (!is_soap_fault($result)) { echo "You have used $result->used_tokens_total "; echo "of your $result->allowed_tokens available tokens.<br>"; } else { echo "SOAP Error: ".$result->faultstring; } $result = $client->__soapCall('Permissions.GetLogins', array('login_search_field'=>'login','login_search_value'=>'')); if (!is_soap_fault($result)) { echo "Here is a list of the Omniture logins in your company: <br>"; foreach ($result as $user) { echo $user->login."<br>"; } } else { echo "SOAP Error: ".$result->faultstring; } // Create a new group $params = array ( 'group_description' => 'My demogroup', 'group_name'=> 'demogroup', 'group_type' => 0, 'groupid' => '', 'perm_info' => '', 'report_categories' => array( 'ecommerce_all'=>0, 'traffic_all'=>0, 'paths_all'=>0, 'custom_paths_all'=>0, 'tools_all'=>0, 'sem_all'=>0 ), 'report_id_list' => array(), 'rsid_list' => array(), 'user_list' => array() ); $result = $client->__soapCall('Permissions.SaveGroup',$params); if (!is_soap_fault($result)) { echo "Group has been created<br>"; } else { echo "SOAP Error: ".$result->faultstring; } ?> </body> </html> |

Not working for me:
Fatal error: Call to undefined function soapclient() in /my/path/to/OmnitureSoapClient.php on line 16
Hi, you need to include the native SOAP client in your PHP installation
http://php.net/manual/en/soap.installation.php
/Henrik
Yes, I am using the native SOAP client.
Well I guess you didn’t enable it in your installation then.
Output from phpinfo() would tell.
/Henrik
Doh, test server did not have it enabled – thanks for your help, code is working perfectly! I am an idiot!
Sorry, that should be:
Fatal error: Call to undefined method SoapClient::soapclient() in /my/path/to/OmnitureSoapClient.php on line 16
No problem
Have fun with it
/Henrik
Henrik, have you ever used this for ReportSuite.Create? I tried:
$result3 = $client->__soapCall(‘ReportSuite.Create’,
array(‘base_currency’=>’USD’,'base_url’=>’testurl.com’,'default_page’=>’index.php’,'duplicate_rsid’=>’template.dev.09′,’go_live_date’=>’2009-08-01 00:00:00′,’hits_per_day’=>’1000′,’latin1′=>’0′,’rsid’=>’myprefix1234test’,'time_zone’=>’12′));
and I get:
SOAP Error: You must specify a Time Zone
- How should the Time Zone be passed to the array?
No I haven’t.
But it looks like you have forgotten the “site_title” parameter.
Guess that is what is causing the trouble.
/Henrik
Once again, you are correct – another one and I’m going to be charged a consulting fee!
I’m glad I could help
Question to anyone using this example – have you successfully sent an array of items in ‘rsid_list’ ? If so, can you post working example code?
If anyone would like to use this with Zend_Soap_Client, make these changes to OmnitureSoapClient.php:
class Core_OmnitureSoapClient extends Zend_Soap_Client {
Function __construct becomes this:
public function __construct($wsdl = null, $username, $secret, $options = null)
{
$this->username = $username;
$this->secret = $secret;
parent::__construct($wsdl,$options);
}
Function __call becomes this:
public function __call($function_name, $arguments) {
$this->addSoapInputHeader($this->getWSSecurityHeader(), false);
return parent::__call($function_name, $arguments);
}
function __soapCall can be removed
Then in the calling code, its
$result = $client->__call
Hi mplong,
when I would use Zend_Soap_Client I have an error: “Invalid authentication credentials.” How can I fix it?
When I use OmnitureSoapClient everything works fine!
Thanks!
Alain
Sorry that should be
class OmnitureSoapClient extends Zend_Soap_Client {