Omniture Web Services

April 12th, 2009 | Tags: , ,

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>
Share and Enjoy:
  • Digg
  • del.icio.us
  • TwitThis
  • StumbleUpon
  • Technorati
  • Netvibes
  • Slashdot
  1. bcolflesh
    July 23rd, 2009 at 14:34
    Reply | Quote | #1

    Not working for me:

    Fatal error: Call to undefined function soapclient() in /my/path/to/OmnitureSoapClient.php on line 16

    • Henrik
      July 23rd, 2009 at 14:39
      Reply | Quote | #2

      Hi, you need to include the native SOAP client in your PHP installation

      http://php.net/manual/en/soap.installation.php

      /Henrik

      • bcolflesh
        July 23rd, 2009 at 14:41
        Reply | Quote | #3

        Yes, I am using the native SOAP client.

        • Henrik
          July 23rd, 2009 at 14:43
          Reply | Quote | #4

          Well I guess you didn’t enable it in your installation then.
          Output from phpinfo() would tell.

          /Henrik

          • bcolflesh
            July 23rd, 2009 at 14:44
            Quote | #5

            Doh, test server did not have it enabled – thanks for your help, code is working perfectly! I am an idiot!

  2. bcolflesh
    July 23rd, 2009 at 14:39
    Reply | Quote | #6

    Sorry, that should be:

    Fatal error: Call to undefined method SoapClient::soapclient() in /my/path/to/OmnitureSoapClient.php on line 16

  3. Henrik
    July 23rd, 2009 at 14:46
    Reply | Quote | #7

    bcolflesh :

    Doh, test server did not have it enabled – thanks for your help, code is working perfectly! I am an idiot!

    No problem :-) Have fun with it

    /Henrik

  4. bcolflesh
    July 28th, 2009 at 19:07
    Reply | Quote | #8

    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?

    • Henrik
      July 28th, 2009 at 19:20
      Reply | Quote | #9

      No I haven’t.
      But it looks like you have forgotten the “site_title” parameter.
      Guess that is what is causing the trouble.

      /Henrik

      • bcolflesh
        July 28th, 2009 at 19:44

        Once again, you are correct – another one and I’m going to be charged a consulting fee!

        • Henrik
          July 28th, 2009 at 19:47

          I’m glad I could help :-)

  5. bcolflesh
    December 15th, 2009 at 15:46

    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?

  6. mplong
    July 21st, 2010 at 21:50

    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

    • Alain
      August 26th, 2010 at 10:38

      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

  7. mplong
    July 21st, 2010 at 21:51

    Sorry that should be
    class OmnitureSoapClient extends Zend_Soap_Client {