Miscellaneous Ramblings on Hacking

July 30, 2010

Unica Interact via SOAP – How To

Filed under: .Net, Unica — Zack Bethem @ 9:50 pm


Unica Interact extends Unica’s Campaign Suite for real-time offer management. If you want a full background of what it can offer, I’d suggest a read from Unica’s site. Here I’ll be discussing how to get started for some real basic integration. First, what you’ll need:

  • Unica’s v7 demo image or access to a Unica Interact implementation
  • Visual Studio 2008 (C# Express should work)

Interact Setup

When using the VMWare demo image provided, most of this is setup as part of the image. As an overview, however, I’ll review the following steps:

  1. Interactive Channel
  2. Session
  3. Assigned Campaign Offers and Ratings

Interactive Channel – Insurance

I’ll be using the already defined interactive channel Insurance. This is part of the Unica v7 demo image available to their partners. This interactive channel represents a website for an Insurance company and is defined with two zones, each with a single interaction point. One for home page landings, which would be the assumed landing page a user would see. Second, a signup page where a user would sign in based on existing credentials and/or register for first time use.


Interactive Session

From within the Interactive Channel summary tab, click on the related session Insurance. This will show the interactive session and its associated flowchart into focus for review.


Reviewing the associated flowchart, we see a simple segmentation of the incoming individual based on their related FICO score. Examining the process box FICO Score, the segmentation is as follows:

Low FICO Score Score < 200
Med FICO Score 200 < Score < 400
High FICO Score Score > 400


Lastly, examining the interaction process box Indiv_Id Profile the expected meta data for a session is shown along with the expected Audience. This will come into play later when the API initiates an interact session. For now, note that the audience level is Individual and the associated key is Indiv_Id. Also note the Score attribute in the record’s metadata used above for segmentation purposes.


Interactive Campaign

The last piece of the Interact puzzle is the associated interact campaign. Here is where the associated offers are defined by segment. I won’t go into the specifics as there is a complete User’s Guide for that, but here is where we can rank our offers. Note that some of the offers listed have expired, which is why they will not be shown later during the coding exercise. Also note that we have some offers tied directly to a given zone and that the offers have an associated ranking for presentation purposes.


Visual Studio Setup

With the review of the interact setup out of the way, it’s time prepare the VS environment for some coding. I’m using C# for this exercise which will limit me to using SOAP. Unica warns that the best performance is achieved using their interact_client.jar, but 1) I’m playing and 2) I’m not concerned with performance right now and 3) C# and .jar wouldn’t work to well and 4) I like C# more that I like java.

Import the WSDL

The WSDL for Interact can be found under:


Be sure to use the file from your installation as a version incompatibility could exist!

Once you have the WSDL downloaded, you can build a DLL out of it by doing the following steps:

  1. As administrator, open a Visual Studio command prompt. This is different from just a normal DOS prompt as it has environment settings. The link is in the start menu under the Visual Studio 2008 folder.
  2. Using the wsdl.exe utility, generate a C# Class
    wsdl /l:CS /protocol:SOAP \InteractService.wsdl
  3. Compile the proxy class as a DLL
    csc /t:library /r:System.Web.Services.dll /r:System.Xml.dll InteractService.cs

Visual Studio C# Console Program

Add a InteractService.DLL Reference

Create a new C# Console program. Once the project structure is created, we’ll reference the DLL that was compiled from above. Once does this by Right-Clicking on the Reference folder in the Solution Explorer window and opting for Add Reference..


Build a Helper Class

I created a helper class in my code. The class is basic as potatoes, but it allows for the quick definition of NameValuePairs. These name-value pairs are important as they define the session’s record structure. Recall I mentioned that earlier in reviewing the session’s metadata.

    class InteractHelper
        public NameValuePairImpl defineParm(string parmName, int valNumeric)
            NameValuePairImpl parm = new NameValuePairImpl();
            parm.name = parmName;
            parm.valueAsNumeric = valNumeric;
            parm.valueDataType = "numeric";
            return parm;
        public NameValuePairImpl defineParm(string parmName, string valString)
            NameValuePairImpl parm = new NameValuePairImpl();
            parm.name = parmName;
            parm.valueAsString = valString;
            parm.valueDataType = "string";
            return parm;
        public NameValuePairImpl defineParm(string parmName, DateTime valDate)
            NameValuePairImpl parm = new NameValuePairImpl();
            parm.name = parmName;
            parm.valueAsDate = valDate;
            parm.valueDataType = "datetime";
            return parm;

Note in the code that there are three defined valueDataTypes for the NameValue pairs. These are:

  1. numeric
  2. string
  3. datetime

Build Console Main()

Keep in mind that this is just a glorified HelloWorld program with the intention to get you started. That being said, the bulk of the code is just thrown into the Main method in the Console Program’s class. Computer Science geeks can check their attitude at the door.

class Program
        static void Main(string[] args)

            InteractService _svc = new InteractService();
            //define the URI for the interact service listening for requests
            _svc.Url = "http://localhost:7001/interact/services/InteractService";

            //this will validate that we connect successfully upon receiving a version
            //number from the service
            getVersionResponse rVersion = _svc.getVersion();

            //setup the name-value pair(s) specifying the audience
            NameValuePairImpl IndivId = new NameValuePairImpl();
            IndivId.name = "Indiv_Id";
            IndivId.valueAsNumeric = 948;
            IndivId.valueDataType = "numeric";
            NameValuePairImpl[] initAudience = { IndivId };

            //setup the expected record structure for the session
            //these values don't have to have values, but the structure must
            //be defined!
            List<NameValuePairImpl> parmList = new List<NameValuePairImpl>();
            InteractHelper hlpr = new InteractHelper();
            parmList.Add(hlpr.defineParm("Score", 250));
            parmList.Add(hlpr.defineParm("HHold_Id", 372));
            parmList.Add(hlpr.defineParm("Head_Of_Hhold", "1"));
            parmList.Add(hlpr.defineParm("Score_Date", DateTime.Now));
            parmList.Add(hlpr.defineParm("Score", 300));
            parmList.Add(hlpr.defineParm("Marital_Status", "Single"));
            NameValuePairImpl[] sessionParms = parmList.ToArray();

            //start the interact session
            Response r = _svc.startSession("123456", false, true, "Insurance", initAudience, "Individual",

            //get available offers for the session
            Response rOffersAvail = _svc.getOffers(r.sessionID, "OnLineInsuranceHomePage", 5);

            //end the program


There are a few things that are important to review. These are represented in the images below.

First, the record structure defined within the Interact session should be in sync with the name-value pair array submitted when initiating an Interact session. This is shown in the image below while using my helper class for defining the Name-Value pair array.

Second, the offers received as part of the session match against the offer rules defined as part of the campaign for the given interaction zone. All offer rules from other campaigns are applied, such as expiration dates rendering an offer invalid. In the example below, I’m showing the program running in debug mode while watching variable assignment. Note that two offers are returned when making the getOffers() request for an individual with a FICO of 300 (aka. segment=MedFICO). The offers suggested are both active across all zones. The other two defined across the zones have both reached their expiration date. As a result, they are not returned.

And that is it. If you haven’t fallen asleep by now, congrats you made it. Hope it helps as you learn Interact. There are some tricky bits that make the getting started process bumpy. This post with the code samples should help you get going faster.


February 24, 2010

Fun with c# and the RightNow API

Filed under: .Net, RightNow — Zack Bethem @ 12:29 am

I wanted to dump out data from RightNow’s Contact tables. The intention was to load a SQL Server table that would then be used in later ETL for data quality rules.

The code does the magic I want.

  • Execute a RightNow report for a range of contacts.c_id values
  • Store the results in a SQL Server table on my local machine

The only problem is performance. SFDC can dump out 2-3million rows in an hour. My code was far from efficient as it was built for a quick-exercise. The code for 1.5million rows would finish in about 14hours. YUCK! Update: I was able to score 760k records in 1.5hrs … much better.

Here’s my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using obj.api.rightnow.com;
using fault.api.rightnow.com;
using api.rightnow.com;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace Becker_DataExtract
    class Program
        static void Main(string[] args)

            RNOWObjectFactory ofactory = new RNOWObjectFactory(Properties.Resources.RNOWConnection);
            ofactory.login(Properties.Resources.RNOWLogin, Properties.Resources.RNOWPass);

            //database stuff
            string connString = "server=(local)\\SQLEXPRESS;Initial Catalog=BeckerPOC;User ID=becker;Password=becker";
            string insertSQL = @"insert into RNContacts(c_id,org_id,last_name,first_name,email,email1,email2,street
,city,prov,postal_code,country,ph_asst,ph_fax,ph_home,ph_mobile,ph_office, RNLastUpdated)
(@c_id, @org_id, @last_name, @first_name, @email, @email1, @email2, @street
,@city, @prov,@postal_code,@country,@ph_asst,@ph_fax,@ph_home,@ph_mobile,@ph_office, @RNLastUpdated)
            SqlConnection conn = new SqlConnection(connString);
            SqlDataAdapter da = new SqlDataAdapter();

            object[][] reportResult;

            System.Console.WriteLine("Staring process: " + DateTime.Now.ToShortTimeString());

            for (int i = 1; i <= 25; i++)
                List<RNOWAcFilter> reportFilters = new List<RNOWAcFilter>();
                RNOWAcFilter reportFilter = new RNOWAcFilter();
                reportFilter.Operator = Convert.ToInt32(RNOWUtil.SearchOperator.RANGE);
                reportFilter.Value = i.ToString() + "|" + (i * 1000).ToString();
                reportFilter.FilterId = 1;
                reportResult = ofactory.ExecuteReport(Convert.ToInt32(Properties.Resources.RNOWExtractReport), reportFilters.ToArray());

                foreach (Object[] result in reportResult)
                    SqlCommand cmdSQL = new SqlCommand(insertSQL, conn);

                    SqlParameter c_id = new SqlParameter("@c_id", Convert.ToString(result[0]));
                    cmdSQL.Parameters.Add( c_id );

                    SqlParameter org_id = new SqlParameter("@org_id", Convert.ToString(result[1]));
                    SqlParameter last_name = new SqlParameter("@last_name", Convert.ToString(result[2]));
                    SqlParameter first_name = new SqlParameter("@first_name", Convert.ToString(result[3]));
                    SqlParameter email = new SqlParameter("@email", Convert.ToString(result[4]));
                    SqlParameter email1 = new SqlParameter("@email1", Convert.ToString(result[5]));
                    SqlParameter email2 = new SqlParameter("@email2", Convert.ToString(result[6]));
                    SqlParameter street = new SqlParameter("@street", Convert.ToString(result[7]));
                    SqlParameter city = new SqlParameter("@city", Convert.ToString(result[8]));
                    SqlParameter prov = new SqlParameter("@prov", Convert.ToString(result[9]));
                    SqlParameter postal_code = new SqlParameter("@postal_code", Convert.ToString(result[10]));
                    SqlParameter country = new SqlParameter("@country", Convert.ToString(result[11]));
                    SqlParameter ph_asst = new SqlParameter("@ph_asst", Convert.ToString(result[12]));
                    SqlParameter ph_fax = new SqlParameter("@ph_fax", Convert.ToString(result[13]));
                    SqlParameter ph_home = new SqlParameter("@ph_home", Convert.ToString(result[14]));
                    SqlParameter ph_mobile = new SqlParameter("@ph_mobile", Convert.ToString(result[15]));
                    SqlParameter ph_office = new SqlParameter("@ph_office", Convert.ToString(result[16]));
                    SqlParameter RNLastUpdated = new SqlParameter("RNLastUpdated", Convert.ToString(result[17]));

                    //da.InsertCommand = cmdSQL;

                System.Console.WriteLine("Done with loop run: " + i.ToString());

            System.Console.WriteLine("End of process: " + DateTime.Now.ToShortTimeString());





Looking at the comments on this post, it appears that I have RightNow checking my code. Yes. there is a bug in it. The idea is to use a report to dump out data. So the start range needs to be incremented more than it is in the AcFilter.

February 17, 2010

C# interacting with a web form

Filed under: .Net, RightNow — Zack Bethem @ 11:45 pm

Sweet.. I love the web. I needed to build a POC for a RightNow project I’m working on. BAZINGA

Not only was it an awesome domain name. But, the code is exactly what I require. THANKS!

January 28, 2009

RNOWOrganization – how to add a parent?

Filed under: .Net, RightNow — Zack Bethem @ 4:04 am

I’m still working with hacking my way through C#. The latest stumbling block is adding an organization with an associated parent organization. The end result would look like the following within RightNow:

To date, I have the following code using the RNOW Data Connection API

// set parent org
if (Convert.ToString(row[38]) != "")
int z = getXrefId(Convert.ToString(row[38]), tblXrefIds);
if (z != 0)
RNOWOrganization parentOrg = new RNOWOrganization(z);
List parentOrgs = new List();
myOrg.Parent = parentOrgs;
//log error

The current question? The code syntax 'myOrg.Parent = parentOrgs;' doesn’t work. Instead, I get the error:
Cannot implicitly convert type ‘System.Collections.Generic.List<int>’ to ‘System.Collections.Generic.List<int?>’

Seems same to me.

Argh!!! Why can it just be a single Integer representing the ID of the organization. A list to set a single parent? What for? Make it simple stupid. The head scratching continues.


Turns out C# provides a way to define a nullable list of collections. This is defined by the ‘?’ notation. So, parentOrgs in the code snippet above had to be defined by:

List<int?> parentOrgs = new List<int?>();
Defining the hierarchy is still not working 100%, but this hurdle is hopped over.

January 7, 2009

RightNow Connect DLL

Filed under: .Net, RightNow, Uncategorized — Zack Bethem @ 2:55 am

I’ve found myself doing some .Net coding these days. A rest from Ruby on Rails (which is friggin’ awesome).

When using the RightNow Connect DLL I always would get the most common error of all..

“Invalid Server Version. Server ‘ ‘. Connect ‘’.”

Scratching my head. I closed the new solution in Visual Studio, which caused the solution’s folder structure to be created. After reopening it and re-pointing the reference to the RightNow Connect DLL. Things seem to work. No problems with that A-N-N-O-Y-I-N-G “invalid server version” message. Viola! It works. Good enough.

Blog at WordPress.com.