jump to navigation

Trials and tribulations of the ET WebServices API June 5, 2008

Posted by mmoriar1 in Uncategorized.
Tags: ,
trackback

Since last time I have implemented a (seemingly working) login system, set up the divs for the first draft of the page layout, validated the email address field, made some magic happen with repeaters, created a cool AJAX collapsible panel, and set up the site map. Extremely long sentence aside, I’ve been pretty productive.

The login system was a tricky fellow to design, but implementation was fairly simple. While not elegant, it IS functional. The tricky parts were figuring out how to authenticate the username/password with the ExactTarget system, how to go about storing the username/password for use in subsequent API calls, and how to prevent unauthenticated users from accessing other parts of the site. These difficulties were overcome by:

  • Performing a dummy API call to the ET servers and seeing if any exceptions are thrown. If an exception was thrown by the authentication, that message is displayed neatly to the user under the two username/password text boxes. If no exception was thrown, then the user is redirected to a start page.
  • Storing the username/password in the Session object. Session is naturally encrypted and is persisted as the user travels from page to page, so it works quite well.
  • Storing a boolean variable in the Session pertaining to whether or not the user has authenticated with the ET servers or not. At the top of each “restricted” page (in the page load), the page checks to see whether the user is authenticated, and if not it redirects to the login page. Despite a few display quirks, it works well.

Setting up the divs for the page layout was nothing more than fiddling with CSS. Here is what the page looks like as of now (draft 1). Ignore the debugging background colors 🙂

Validating the email field was quite easy as well after watching a tutorial video on the subject. (http://asp.net/learn/videos/video-193.aspx) It just makes sure that something is in the box using the RequiredFieldValidator and makes sure that it follows the name@site.domain format using the RegularExpressionValidator.

The magic with repeaters was fun. The idea was to fetch a Subscriber’s attributes (First Name, Last Name, Email, etc.) on page load and then display the attributes in editable text boxes so that a user could change their value(s), and then the Subscriber could be updated with an API call to the ET server. After debugging a few frustrating errors in the API/C# (discussed below), I loaded the Subscriber’s attributes into an ArrayList which was then bound to a repeater (guide consulted: http://stanleycn.blogspot.com/2006/10/how-to-bind-arraylist-to-repeater.html). The repeater simply displayed each attribute’s name on a label followed by a text box pre-populated with the attribute’s value. The result can be seen in the above image. One other thing that had to be done was to cast the Container.DataItem object in the repeater template to an attribute object like so: ((com.exacttarget.webservice.Attribute)Container.DataItem).

The AJAX in the page so far is little more than an UpdateProgress control used to visually indicate when the client is requesting stuff from the server (resources used: http://asp.net/learn/ajax-videos/video-123.aspx for the guide and http://ajaxload.info/ for the awesome animated gif) and a CollapsiblePanelExtender in order to hide/show the source code for the API call (guide: http://asp.net/learn/ajax-videos/video-89.aspx)

One time consuming debug that I had to do stemmed from the fact that in the API Guide example code on page 40 there is the line:

PartnerAPI.Send send = results[cntr] as Send;

which I reformed to say:

PartnerAPI.Subscriber sub = results[cntr] as Subscriber;

Seems OK, right? All of the rest of my code was correct, but I kept getting the compilation error that “it could not convert com.exacttarget.webservice.APIObject to Subscriber via an internal conversion”. But it had worked the previous day in its current state…hmmm… Well, after trying stuff, it turns out that it needed to be declared as such:

com.exacttarget.webservice.Subscriber sub = results[cntr] as com.exacttarget.webservice.Subscriber

Yep, fully qualified and all. Still haven’t figured out totally why that is, but it works and is pretty low on my priority list to clean it up.

The other time consuming bug which hit me was that when trying to grab a subscriber’s attributes, I would include “Attributes” in the properties list as such:

sub_request.Properties = new string[] { “ID”, “EmailAddress”, “Attributes” };

This makes sense, as Attributes are a member of the Subscriber object and are returned as an array of the Attribute object. But upon performing the retrieve call, I would get an error indicating that “the format doesn’t match the form’s field view” (or something similar). This is because you aren’t supposed to include “Attributes” in the properties list, as they are grabbed by default. I stumbled upon this fix in the developers.exacttarget.com forum. Problem solved.

Well that’s all for now, until next time,

Mike

Advertisements

Comments»

1. mike - January 21, 2009

i am having one hell of a time trying to get a list of attributes for a subscriber via this API. I read your comment about not including the Attributes name in the properties array list (which i have not) but all my attributes are returning as null when i do the subscriber retrieve.

basically.
RetrieveRequest listsub_request = new RetrieveRequest();
listsub_request.ObjectType = “Subscriber”;
listsub_request.Filter = sfp;

string[] ls_props = new string[] { “SubscriberKey”};
listsub_request.Properties = ls_props;

APIObject[] results;
string status = “”;
string requestID = “”;
status = api.Retrieve(listsub_request, out requestID, out results);

Subscriber sub = results[0] as com.exacttarget.webservice.Subscriber;

As you can see i am creating a RetrieveRequest for a Subscriber type? is this even correct. Attributes are null but the email address and what not is returned. You state that working with subscribers and getting their info is pretty straightforward but i have been doing this for two days and i find it anything but.

Please provide some sort of full example on how we can get a users properties and attributes from teh system. It seems like this would be one of the first things documented – we want to build a profile update form that does NOT use your profile center.

thanks in advance,

mmoriar1 - January 21, 2009

Hi Mike,

I’ll try and get that to you but you should know that my internship at ExactTarget is over and I do not have the in-depth knowledge of someone on the Developer Community (now called 360 I believe). Did you try posting your question there?

I’ll have to look at my code again and I’ll try and get you something within the next day.

Thanks,
Michael

2. mike - January 21, 2009

thanks for the comment. yes i tried posting there. last activity was 20 hours ago and it was me ! now i cant even post a message (started antoher ticket in there)

I do have a question perhaps you can answer. THe IsRetrievable property is false for all my custom attributes. Could that be the reason why they constantly return null? if so how can i set these custom attributes to be retrievable?

thanks again,
mcm

3. mmoriar1 - January 22, 2009

You might try checking the properties on the attributes in the ET Application itself. I’m in the process of getting an account for WebServices debugging so I can’t help much until then.

Good luck, hopefully I’ll get back to you soon,
Mike

4. mike - January 22, 2009

thanks for the help. dont worry about it though i got it sorted.
the isretrievable prop seems to do nothing (at least with the API)
there was a config error on the ET side and they addressed the issue although they did not get back to me like promised.

I simply re-tried the same RetrieveRequest for a subscriber object and all the attributes were included today.

go figure.

John Jones - March 17, 2010

here is my code..
private string GetPinCode(string strSubscriber)
{
RetrieveRequest rr = new RetrieveRequest();
rr.ObjectType = “Subscriber”;
string[] ls_props = new string[] { “SubscriberKey”, “Subscriber.ID” };
rr.Properties = ls_props;
APIObject[] objs = null;
string substatus = string.Empty;
string reqID;

SimpleFilterPart subFilter = new SimpleFilterPart();
subFilter.SimpleOperator = SimpleOperators.equals;
subFilter.Property = “SubscriberKey”;
subFilter.Value = new string[] { strSubscriber };
rr.Filter = subFilter;

substatus = Parent.Client.Instance.Retrieve(rr, out reqID, out objs);

return ((Subscriber)(objs[0])).Attributes[26].ToString();

}

mmoriar1 - March 19, 2010

What exactly is the issue you’re having?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: