Getting Started with the Connect SOAP API

This chapter provides an overview of the Xactly Connect application development process including how to download the Xactly Connect WSDL files, how to enable user access, and how to generate the application programming interface objects.

The chapter also provides a cut-and-paste tutorial and explains the sample applications included with the toolkit.

This chapter contains the following topics:

• Xactly Connect Development Overview
• Downloading the Xactly Connect WSDL File
• Enabling User Access
• Generating the Application Programming Interface Objects
• Creating an Xactly Connect Java Application
• Creating an Xactly Connect Microsoft .NET Application
• Performing Error Handling

Xactly Connect Development Overview

Developing an Xactly Connect application involves enabling user access, using the Xactly Connect WSDL files to generate the application programming interface objects, and integrating the API with your client application.

The following figure shows an overview of the Xactly Connect development process.

Screen Shot 2016-07-26 at 8.59.39 AMXactly Connect Development Overview 

The following describes the procedure for creating an Xactly Connect client application:

  1. Download the WSDL file.
    Xactly Connect offers a unified WSDL file for integrating your applications with Xactly Incent and Modeling. For more information, see “Downloading the Xactly Connect WSDL File”.
  2. Enable user access to Xactly Connect.
    You need to assign the Connect Administrator role to a user to provide user access to Xactly Connect. For more information, see “Enabling User Access”.
  3. Generate the Xactly Connect application programming interface objects.
    Client applications access the Xactly Connect SOAP API through proxies for server-side components. You must generate these objects using the Xactly Connect WSDL file before accessing the API.
    For more information, see “Generating the Application Programming Interface Objects”.
  4. Create the client application using the Xactly Connect objects.
    For more information, see “Creating an Xactly Connect Java Application”.

Downloading the Xactly Connect WSDL File

To access Xactly Connect Web services for Xactly Incent or Xactly Modeling, you need the Xactly Connect Web Services Description Language (WSDL) file. The WSDL file defines the Web services available for use in your applications.

The Xactly Connect WSDL file (and sample code) is available through the Xactly Incent online help. To download the WSDL file, log in to Xactly Incent using your account, and click the Help button. The WSDL file and code samples are available in the Administration resources section.

After you have downloaded the WSDL file, you can generate the API suitable for your development environment. For more information about the WSDL file, see “Understanding the Xactly Connect WSDL File”.

note: Open the WSDL file and verify that the wsdlsoap:address tag (location attribute) points to the appropriate URL. For example, to connect to your production instance, use the following URL:

https://www.xactlycorp.com/icm/services/DiscoveryService The protocol must be https.

Enabling User Access

Xactly Connect manages security through the user role assigned in Xactly Incent or Modeling. This means that client applications that access your organization’s Incent data are secured using the same protections as those offered in the Xactly Incent user interface.

To provide an Xactly Incent user access to Xactly Connect, you need to assign the Xactly Connect privilege to the user’s role. The Xactly Connect privilege offers access to the Xactly Connect API.

note: The Xactly Connect privilege provides access to log in to the API, but other page privileges, such as Quotas for example, determine which objects and operations can be accessed and performed using the API.

To enable Xactly Connect user access, do the following:

  1. Log in to Xactly Incent.
  2. Create a new role.
    1. Click the Setup tab then click Roles in the secondary menu. The “Main Roles” screen appears.
    2. Enter a role name such as “Connect Administrator”.
    3. Check the Accessible box next to the Xactly Connect privilege.
    4. Click the Save button.
  3. Assign the Connect Administrator role to a user.
    1. Click the Setup tab then click Users in the secondary menu. The “Main Users” screen appears.
    2. Select the user in the list.
    3. Highlight the Connect Administrator role in the Available Roles section.
    4. Click the < button to move the role to the Assigned Roles section.
    5. Click the Save button.
  4. Log out of Xactly Incent.
  5. Log in to Xactly Incent as the Connect Administrator user and reset the initial password. The user now has access to the Xactly Connect APIs.

Generating the Java API Objects

Java-based applications access the Xactly Connect API through Java objects that serve as proxies for their server-side counterparts. Before using the API, you must generate these Java objects using the Xactly Connect WSDL file.

The following figure shows the steps for generating and including the Xactly Connect API objects into Java-based client applications used in the Apache Axis environment.

Screen Shot 2016-07-26 at 9.27.52 AMIncluding the Java API Objects

To generate the Java API objects, do the following:

  1. Generate the Java API using the Xactly Connect WSDL file.
    Use the Wizard-based tool that is part of your Java development environment to generate the API using the Xactly Connect WSDL file.
    If your development environment does not offer this capability, or you prefer to use a command line utility, do the following:

    1. Verify that you have Apache Axis installed on your system and that all of the component JAR files are included in the classpath.
    2. Run the WSDL2Java utility.
      The WSDL2Java utility generates a set of folders and Java source files in the directory in which the command is run. The syntax for the WSDL2Java is:java -classpath pathToFirstJAR/FirstJARFilename; pathToSecondJAR/SecondJARFilename org.apache.axis.wsdl.WSDL2Java pathToWsdl/WsdlFilenameFor more information about using the WSDL2Java utility, refer to the following
      URL: http://ws.apache.org/axis/java/reference.html
  2. Compile the Java API source files using your development environment.
  3. Include the compiled Java API files in your Java program when creating your Xactly Connect client applications.

Generating the API Objects for Microsoft .NET

Visual Studio languages access the Xactly Connect API through objects that serve as proxies for their server-side counterparts. Before using the API, you must generate these objects using the Xactly Connect WSDL file.

The following figure shows the steps for generating and including the Xactly Connect API objects into Microsoft .NET-based client applications.

Screen Shot 2016-07-26 at 9.31.56 AMIncluding the API Objects Using Microsoft .NETs

Note that an XML Web service client is any component or application that references and uses an XML Web service. This does not necessarily need to be a client-based application. In fact, in many cases, your XML Web service clients might be other Web applications, such as Web Forms or even other XML Web services.

When accessing XML Web services in managed code, a proxy class and the .NET Framework handle all of the infrastructure coding.

note: Visual Studio enables you to use either the IDE or the command line to import the WSDL file and generate an XML Web service client.

To generate the API objects for Microsoft .NET, do the following:

  1. Add a Service reference to your project for the XML Web service that you want to access.
    The Service reference creates a proxy class with methods that serve as proxies for each exposed method of the XML Web service.

    1. Choose Project > Add Service Reference from the main menu. The Add Service Reference dialog box appears,
    2. In the URL field, type the URL to obtain the service description of the XML Web service you want to access, for example:file:///c:\WSDLFiles\DiscoveryService.wsdl
    3. Click the Go button. The system retrieves information about the XML Web service.
    4. In the Service Reference Name field, rename the Service reference to XService. This is the namespace you use for the Service reference.
    5. Click the Add Reference button to add a Service reference for the target XML Web service.
      Visual Studio retrieves the service description and generates a proxy class to interface between your application and the XML Web service. For more information, see the topic “Adding and Removing Web References” in the Visual Studio documentation.
  2. Add the namespace for the Service reference.
  3. Create an instance of the proxy class and then access the methods of that class as you would the methods of any other class.

When you build client-side stubs using Visual studio or other IDEs for a WSDL file, the .NET platform treats Java Date and Number types as complex types. This causes Date and Number types to fail to persist when using VB or C#.

For every Date and Number property, the .NET platform generates an additional property called xxxSpecified, where xxx is the property name. When you populate values into these fields, make sure that you set the xxxSpecified properties to True.

For example, the OrderStageWSO object has a property to set the order date. When you set a value for this property, make sure that you also set the orderDateSpecified property to True.

Creating an Xactly Connect Java Application

This section explains how to create a simple Java-based Xactly Connect application to log into Xactly Incent and search for a user batch using a cut-and-paste tutorial. The following is the complete listing for the tutorial application, followed by an expla- nation of the principal sections:

/**
 * The client logs in and searches for a User Batch object
 */

import org.apache.axis.client.Stub;
import com.xactly.icm.xtoolkit.service.XService;
import com.xactly.icm.xtoolkit.service.XServiceServiceLocator;
import com.xactly.icm.xtoolkit.service.DiscoveryServiceSoapBindingStub;
import com.xactly.icm.xtoolkit.wso.ErrorCode;
import com.xactly.icm.xtoolkit.wso.LoginResponse;
import com.xactly.icm.xtoolkit.wso.SearchResponse;
import com.xactly.icm.xtoolkit.wso.UserBatchWSO;
import com.xactly.icm.xtoolkit.wso.XObject;

public class FirstXServiceClient {
   public static void main(String args[]) throws Exception {

 Screen Shot 2016-07-26 at 9.39.46 AM  XService service = new XServiceServiceLocator().
       getDiscoveryService(new java.net.URL(
       "http://www.xactlycorp.com/icm/services/DiscoveryService"));
      ((DiscoveryServiceSoapBindingStub)service).setMaintainSession(true);

      String username = "demouser@xactlycorp.com";
      String password = "password";

      GatewayResolutionResponse gatewayResponse = 
         service.resolveGateway(username);
      String gatewayUrl = gatewayResponse.getGatewayUrl();
      System.out.println("Resolved Gateway URL for Authentication:" 
         + gatewayUrl);
      ((DiscoveryServiceSoapBindingStub) service).
         _setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, gatewayUrl);

      LoginResponse response = service.login(username, password, "Incent");

      ((DiscoveryServiceSoapBindingStub) service).clearHeaders();
Screen Shot 2016-07-26 at 9.42.54 AMString sessionId = response.getSessionId();
String serverUrl = response.getServerUrl();

      
      ((DiscoveryServiceSoapBindingStub) service).
         _setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, serverUrl);
      ((DiscoveryServiceSoapBindingStub) service).
         setHeader(new XServiceServiceLocator().getServiceName().
         getNamespaceURI(), "SessionId", sessionId);
      ((DiscoveryServiceSoapBindingStub) service).
         setHeader(new XServiceServiceLocator().getServiceName().
         getNamespaceURI(), "UserName", username);

      if (!response.isAuthenticated()) {
         System.out.println("Login failed.");
         ErrorCode errorCode = response.getErrorCodes();
         if (errorCode != null) {
            System.out.println("Code :" + errorCode.getCode());
            System.out.println("Reason :" + errorCode.getReason());
            System.out.println("Stack Trace : " + errorCode.getStackTrace());
         }
         System.exit(-1);
      }

      UserBatchWSO userBatch = new UserBatchWSO();
      userBatch.setBatchName("BATCH-DEC-2006");
Screen Shot 2016-07-26 at 9.44.00 AMSearchResponse searchResponse = service.search(userBatch);
XObject[] results = searchResponse.getSearchRecords();

      
      for (int i=0; i < results.length; i++) {
         UserBatchWSO batch = (UserBatchWSO)results[i];
         System.out.println(batch.getBatchName());
         System.out.println(batch.getDescription());
      }
   }
}

Step 1: Getting an Instance of XService

The first step involves getting an the instance of XService using the XServiceSer– viceLocator (generated by Axis). The second line of the code segment instructs the system to maintain the session.

XService service = new XServiceServiceLocator().
getDiscoveryService(new java.net.URL(
   "http://www.xactlycorp.com/icm/services/DiscoveryService"));

((DiscoveryServiceSoapBindingStub)service).setMaintainSession(true);

Step 2: Logging into the Xactly Connect Server

After getting an instance of the service object, the next step involves resolving the appropriate gateway and logging into the Xactly Connect Server. The login method returns a LoginResponse object.

String username = "demouser@xactlycorp.com";
String password = "password";

GatewayResolutionResponse gatewayResponse = 
   service.resolveGateway(username);
String gatewayUrl = gatewayResponse.getGatewayUrl();
System.out.println("Resolved Gateway URL for Authentication:" 
   + gatewayUrl);
((DiscoveryServiceSoapBindingStub) service).
   _setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, gatewayUrl);

LoginResponse response = service.login(username,password, "Incent");
((DiscoveryServiceSoapBindingStub) service).clearHeaders();

String sessionId = response.getSessionId();
String serverUrl = response.getServerUrl();

((DiscoveryServiceSoapBindingStub) service).
   _setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, serverUrl);

((DiscoveryServiceSoapBindingStub) service).setHeader(new
   XServiceServiceLocator().getServiceName().getNamespaceURI(),
   "SessionId", sessionId);

((DiscoveryServiceSoapBindingStub) service).setHeader(new
   XServiceServiceLocator().getServiceName().getNamespaceURI(),
   "UserName",username);

if (!response.isAuthenticated()) {
   ...
}

Step 3: Searching for a UserBatch Object

After logging into the Xactly Connect Server, the application is able to perform the principal operation of the example, which is to search for a UserBatch Object. The search method returns a SearchResponse object containing an array of the searched object.

UserBatchWSO userBatch = new UserBatchWSO();
userBatch.setBatchName("BATCH-DEC-2006");

SearchResponse searchResponse = service.search(userBatch);

XObject[] results = searchResponse.getSearchRecords();
for (int i=0; i < results.length; i++) {
   UserBatchWSO batch = (UserBatchWSO)results[i];
   System.out.println(batch.getBatchName());
   System.out.println(batch.getDescription());
}

Creating an Xactly Connect Microsoft .NET Application

This section explains how to create a simple Microsoft .NET-based Xactly Connect application to log into Xactly Incent and search for a user using a cut-and-paste tutorial. The following is the complete listing for the tutorial application, followed by an explanation of the principal sections:

using System;
   using System.Collections.Generic;
   using System.Text;
   using System.Reflection;
   using System.IO;

namespace XService {
   class SearchObjects {
      public static int Main(string[] arg)  {
         SearchObjects toolkitClient = new SearchObjects();
Screen Shot 2016-07-26 at 9.39.46 AM    XService.XServiceClient client = new
            XService.XServiceClient("DiscoveryService",
            "http://www.xactlycorp.com/icm/services/DiscoveryService");

            string username = "username";
            string password = "password";
 Screen Shot 2016-07-26 at 9.42.54 AM   XService.loginRequest request = 
            new XService.loginRequest(username, password, "Incent");
         XService.loginResponse1 response = client.login(request);
         toolkitClient.log(response);
         XService.LoginResponse lResp = response.loginReturn;
         client = new XService.XServiceClient("DiscoveryService", 
            lResp.serverUrl)
 Screen Shot 2016-07-26 at 9.44.00 AM   XService.UserWSO user = new XService.UserWSO();

         user.email = "xactly";
         XService.SearchResponse searchResponse = service.search(user);
         toolkitClient.log(searchResponse);
Screen Shot 2016-07-26 at 9.57.10 AM    if (!searchResponse.result) {
            XService.XObject[] objects = searchResponse.searchRecords;
            for (int i = 0; i < objects.Length; i++) {
               user = (XService.UserWSO)objects[i];
               toolkitClient.log("----- Search Result -----");
               toolkitClient.log("Name: " + user.name);
               toolkitClient.log("email: " + user.email);
            }
         }

         return 0;
      }
   }
}

Step 1: Getting an Instance of XService

The first step involves getting an instance of XService.

XService.XServiceClient client = new
   XService.XServiceClient("DiscoveryService",
   "http://www.xactlycorp.com/icm/services/DiscoveryService");

Step 2: Logging into the Xactly Connect Server

The next step involves logging into the Xactly Connect Server.

string username = "username";
string password = "password";

XService.loginRequest request = new XService.loginRequest(username,
   password, "Incent");

XService.loginResponse1 response = client.login(request);
XService.LoginResponse lResp = response.loginReturn;
client = new XService.XServiceClient("DiscoveryService", lResp.serverUrl);

Step 3: Setting the Search Criteria

This step creates a new UserWSO object and sets the search criteria for the user email to xactly. This instructs the search method to find all users that have xactly as part of their email address.

XService.UserWSO user = new XService.UserWSO();
user.email = "xactly";

Step 4: Searching for Users

The final step uses the search method to locate all users that have Xactly as part of their email address and then iterates through the searchResponse object to extract the name and email address for each matching user.

XService.SearchResponse searchResponse = service.search(user);
toolkitClient.log(searchResponse);
if (!searchResponse.result) {
   XService.XObject[] objects = searchResponse.searchRecords;
   for (int i = 0; i < objects.Length; i++) {
      user = (XService.UserWSO)objects[i];
      toolkitClient.log("----- Search Result -----");
      toolkitClient.log("Name: " + user.name);
      toolkitClient.log("email: " + user.email);
   } 
}

Performing Error Handling

Xactly Connect uses the ErrorCode object as the basic error handling object. Response objects returned by the Xactly Connect API embeds an array of ErrorCode objects.

The ErrorCode object has three attributes:

  • A code
  • An error message (reason)
  • A string representation of the stack trace

The following shows the ErrorCode class:

public class ErrorCode implements java.io.Serializable {
   private java.lang.Integer code;
   private java.lang.String reason;
   private java.lang.String stackTrace;

   public ErrorCode() {
   }

   public ErrorCode(
      java.lang.Integer code,
      java.lang.String reason,
      java.lang.String stackTrace) {
         this.code = code;
         this.reason = reason;
         this.stackTrace = stackTrace;
      }
      .
      .
      .
}

Example

This section presents an example of how to perform error handling following a login operation using an incorrect password. The following is the complete listing for the example, followed by an explanation of the error handling:

import org.apache.axis.client.Stub;

import com.xactly.icm.xtoolkit.service.XService;
import com.xactly.icm.xtoolkit.service.XServiceServiceLocator;
import com.xactly.icm.xtoolkit.wso.ErrorCode;
import com.xactly.icm.xtoolkit.wso.LoginResponse;
import com.xactly.icm.xtoolkit.service.DiscoveryServiceSoapBindingStub;

public class LoginUser {
   public static void main(String args[]) throws Exception {
      // Locate the Service and maintain session
      XService service = new XServiceServiceLocator().getDiscoveryService(new 
         java.net.URL("http://www.xactlycorp.com/icm/services/DiscoveryService"));
      ((DiscoveryServiceSoapBindingStub) service).setMaintainSession(true);
Screen Shot 2016-07-26 at 9.39.46 AM String username = "xconnect@xactlycorp.com";
      String password = "invalidPassword";

      GatewayResolutionResponse gatewayResponse = 
         service.resolveGateway(username);
      String gatewayUrl = gatewayResponse.getGatewayUrl();
      System.out.println("Resolved Gateway URL for Authentication:" 
         + gatewayUrl);
      ((DiscoveryServiceSoapBindingStub) service).
         setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, gatewayUrl); 

      LoginResponse response = service.login(username,password,"Incent");
      ((DiscoveryServiceSoapBindingStub) service).clearHeaders();

      String sessionId = response.getSessionId();
      String serverUrl = response.getServerUrl();

      // Change the endpoint URL of the service and set session header.
      // The endpoint URL is similar to the following:
      // http://www.na1.xactlycorp.com/xiconnect/services/XService

      ((DiscoveryServiceSoapBindingStub) service).
         _setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, serverUrl);
      ((DiscoveryServiceSoapBindingStub) service).
         setHeader(new XServiceServiceLocator().getServiceName().
         getNamespaceURI(), "SessionId", sessionId);

      ((DiscoveryServiceSoapBindingStub) service).
         setHeader(new XServiceServiceLocator().getServiceName().
         getNamespaceURI(), "UserName", username);
Screen Shot 2016-07-26 at 9.42.54 AM if (!response.isAuthenticated()){
         System.out.println("Login failed. Error code below.");
         ErrorCode errorCode = response.getErrorCodes();
         if (errorCode != null) {
            System.out.println("Error Code: " + errorCode.getCode());
            System.out.println("Reason: " + errorCode.getReason());
         } 
      } else
         System.out.println("User Logged in Successfully");
      } 
   }

The example produces the following output:

   Login failed. Error code below.
   Error Code: 1224
   Reason: Login Failed. Please try again.

Section 1: Invoking the login Operation

The example invokes the Service login method, and a LoginResponse object is returned. The LoginResponse object has a authenticated field that is set to true when a user have been successfully authenticated.

Section 2: Extracting ErrorCode Information

The example checks the LoginResponse object to determine if authentication has completed successfully. If authentication fails, the ErrorCode object is read from the LoginResponse object. Using the ErrorCode object, the example retrieves the error code and reason (error message) for display.