Sample Code

This sample PHP code illustrates the use of the SAINT API. Each PHP code sample demonstrates the use of a SAINT method.
  • Before working with the code samples, download the Online Marketing Suite WSDL. This file is available in SiteCatalyst. Browse to Admin Console > Company > Web Services, then select the WSDL link to download the file.
  • You must have Web Service Access to SiteCatalyst to use the SAINT API (or any other Online Marketing Suite Web service). Your organization's SiteCatalyst administrator can do this in Admin Console > User Management. For more information, see "User Management" in the Administration Console User Guide.
  • When a user has Web Services Access, SiteCatalyst generates a Web Services Username and Shared Secret for the user. This information must be assigned to the $username and $secret variables in the PHP code samples.

The Web Services username and shared secret are extremely confidential and sensitive values. Do not share this information with anyone.

The SAINT code samples rely on the following:
  • NuSOAP - SOAP Toolkit for PHP: The PHP code samples were created using the NuSOAP SOAP Toolkit for PHP. For more information, visit the NuSOAP Project website.
  • OM_Soap.inc: The PHP code samples rely on an include file entitled OM_Soap.inc. It is included here for your convenience.

#!/usr/local/bin/php -q
<?
/**
 * @file
 * OM_SoapClient
 * Copyright 2009-2010 Adobe Systems, Inc. All Rights Reserved.
 **/

require_once 'nusoap/nusoap.php';

class OM_SoapClient {
  /** @privatesection */
  var $_soap_client;
  var $_debug_level = 0;
  var $_username;
  var $_secret;
  var $_company;
  var $_wsdl_doc;
  var $_debugLevel;
  var $response;

  function getHeader() {
    $username     = $this->_username;
    $secret       = $this->_secret;
    $nonce        = md5(rand());
    $created      = date("Y-m-d H:i:s");
    $combo_string = $nonce . $created . $secret;
    $password     = base64_encode(sha1($combo_string));

    $headers = '
      <wsse:Security SOAP-ENV:mustUnderstand="1">
        <wsse:UsernameToken wsu:Id="User">
          <wsse:Username>' . $username . '</wsse:Username>
          <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">' . $password . '</wsse:Password>
          <wsse:Nonce>' . $nonce . '</wsse:Nonce>
          <wsu:Created>' . $created . '</wsu:Created>
        </wsse:UsernameToken>
      </wsse:Security>';
    if ($this->_company !== NULL) {
      $headers .= sprintf('<AdminInfo><company>%s</company></AdminInfo>', $this->_company);
    }
    return $headers;
  }

  /** @publicsection */
  /**
   * OM_SoapClient Constructor
   *
   * @return (void)
   */
  function OM_SoapClient($username, $secret, $company=NULL) {
    $this->_username = $username;
    $this->_secret = $secret;
    if ($company !== NULL) {
      $this->_company = $company;
    } else {
      $this->_company = NULL;
    }
    $this->_debugLevel = 0;
  }

  function &getSoapClient() {
    if ($this->_soap_client === NULL) {
      if ($this->_wsdl_doc !== NULL) {
        $this->_soap_client = new NU_soapclient($this->_wsdl_doc, true);
      } else {
        $this->_soap_client = new NU_soapclient();
      }
    }

    $this->_soap_client->debugLevel       = $this->_debugLevel;
    $this->_soap_client->soap_defencoding = 'UTF-8';
    $this->_soap_client->decode_utf8      = FALSE;

    return $this->_soap_client;
  }

  function setDebugLevel($value) {
    $this->_debugLevel = $value;
  }

  function setWSDL($wsdl) {
    $this->_wsdl_doc = $wsdl;
  }

  function call($call, $parameters) {
    $soap_client =& $this->getSoapClient();
    $header = $this->getHeader();
    $response = $soap_client->call($call, $parameters, 'https://www.omniture.com/p/am/1.2/soap.html?MainIndex', '', $header);

    if ($soap_client->fault) {
      return FALSE;
    } else {
      $this->setResponse($response);
      return TRUE;
    }
  }

  function &getResponse() {
    return $this->response;
  }

  function setResponse(&$response) {
    $this->response =& $response;
  }

  function getError() {
    $soap_client =& $this->getSoapClient();
    return $soap_client->getError();
  }

  function getDebugInfo() {
    $client =& $this->getSoapClient();
    if ($this->_debugLevel > 0) {
      print "Debug:\n";
      print $client->debug_str;
    }
    print "Request:\n";
    print $client->request;
    print "Response:\n";
    print $client->response;
  }
} // END class OM_SoapClient
?>

Comments (0)

Must be logged in to comment. or register now to comment!