splash
Welcome
Hi @everyone. If you are interested in stuff such as .Net, SharePoint, PowerShell, Mobile and Social Media you´ve come to the right place!
Posted By Markus on April 16th, 2010

Today I´ve been with a customer and ran into a problem using the “Update AD Account” activity. One scenario was to manage AD Accounts with the help of SharePoint Lists and Nintex Workflow. Anyways, it was necessary to maintain the “AccountExpirationDate” property of AD accounts. Unfortunately there´s no way to do that by default with [...]

 

Automate Twitter with Nintex Workflow – I

Posted By Markus on März 2nd, 2010

In my last post I described how I´ll try use workflows and lists to build service-like behaviour to automatically add Twitter users to my “following” list.

To get this done, we need to take a closer look at how to use Nintex Workflow to place web requests and how Twitters own search engine is working.

The Twitter Part

Let´s begin with Twitter search. There´s a special search page on Twitter, go here!

If you place a search (i.e. for sharepoint), the url changes to

…and we can see the HTML result for that search

What we need is sort of an XML result, that´s much easier to analyze than plain HTML. Take a look at the right part of the page, I marked “Feed for this query”. If you click on that, you notice a new url:


   
 

“search.atom” means we get an XML result, so we hook here and try to make a request to this url with Nintex! Also keep in mind the URL parameters.

The Nintex Part

We use the “Web Request” action to take a first shot. Drag it onto the Workflow Designer and open its configuration dialog.


There´s only a few mandatory fields we need to configure here:

  • URL
  • Username and password (use a WF constant here)
  • Create a WF variable to catch the web result

In the lower part of the action, you will find the “Store result in” option. Here we use a WF variable (of type “Text”) to save the result string from the response.


At this point I publish the WF and let it run manually. In a later post I will describe in detail how we have to design the workflow entirely. If we take a look at the value of our result parameter, we recognize the schema of the xml result.

<feed>
  <entry>
   <author>
      <name>markusalt (Markus Alt) </name>
      <uri>http://twitter.com/markusalt </uri>
    </author>
  </entry>
</feed>

As you can see, the schema is pretty easy. What we need to do next is to extract the username, either from the <name> or the <uri> node. We will need the username later to add a user to the “following” list. Nintex Workflow comes with an action called “Query XML” which fits our purpose.

The beauty here is that you can use XPATH to extract data you need from the xml source. Since we understood the xml schema, we can build a tiny XPATH query to get to the data. A fitting XPATH epxression to the <name> node would be: //feed/entry/author/name

The configuration dialog would look like this

 

You see I use a new WF variable (of type “Collection”) to store the result. We need to use a collection variable since we will most likely get more than one username from the query. So, at this moment the first WF looks like this

There´s not that much happening so far. We build the query string based on a certain hashtag, post a search request to Twitter and try to get a collection of corresponding usernames into a variable. With the last action I simply “log” the value to the WF history as a comment. If we run the WF there will be no value in the variable (no usernames inside the variable).

Surprised? Not really, because there is a default namespace living inside the XML – Xpath does not like that. We have to use a trick to get rid of that default namespace. If you want to find and replace such values within a Nintex Workflow, you have to use the “Regular Expression” action. In our case, we need to erase xmlns=http://www.w3.org/2005/Atom . Use the following configuration to do that:


With this action, we simply override our “result” variable with the same XML data as before, but without the default namespace! Finally WF looks like this

If we start the WF one more time, we can see that the usernames are listed now within the workflow comments (cut off, because of a 255 character limitation of the comment field) J

You see it´s a little tricky to get to webservice data at hand with Nintex, but if you know how to handle XML with the right WF Action it works like a charme! In the following parts, I will describe how we can create a generic SharePoint structure to handle multiple hashtags and how to use WF scheduling to automatically do searches and add users to the “following” list.

Markus

Tags: , , ,

Similar Posts
Posted in SharePoint

2 Responses to “Automate Twitter with Nintex Workflow – I”

Trackbacks

  1. Kylie Batt
  2. Kylie Batt

Leave a Reply