• vadim@workflowexcellence.com
  • Utah, United States

Nintex Workflow – Shorten URL User Defined Action

As I work through a process of automating my blog announcements using Nintex Workflow, I’ve hit a few snags.  First was the previous post – Nintex Workflow URL Encoding User Defined Action.

I’ll be sharing my findings in automating this process through some posts on here, and hopefully breaking it up into User Defined Actions so that others can reuse these.

Some of you are aware of Twitter and it’s 140 character limit.  Some of my urls can be quite large, so tweeting about a new blog post can quite quickly reach the 140 character maximum.  I needed to find a way to shorten the url, but this had to be done in an automated fashion.

The good folks at to.ly expose a API that will shorten a URL. For those that are interested, here is a link to their API – http://to.ly/api_info.php

Example

The aim is to convert a url like this : “http://vadimtabakman.com/nintex-workflow-url-encoding-user-defined-action.aspx” which is about 78 characters, into some thing small, like http://to.ly/lR84 which is only 17 characters.

Conversion

The original url would take up more than half the space available for a tweet.

Technical Explanation of the User Defined Action

To call to.ly, use a Web Request action, configured to perform a POST to the following URL : http://to.ly/api.php?json=1&longurl=Input URL&callback=?

The Input_URL is a url encoded url that you need shortened.  We also configured the Web Request action to store the HTTP Status so that we can make sure the call worked correctly, making out UDA robust.

Web Request

If the status returned is 200, it was a successful call.  If it’s not, we set a return parameter in our UDA so that the calling workflow can cater for this.

When processing the response, you get some JSON data, which we would then need to parse to pull out the shortened url.  Here is what the response will look like:

Web Request Response

To extract the shorturl, we can use a Regular Expression action, with this expression : (?<=”: “)[\w\W]+(?=”, “)

Regular Expression

There’s a couple more actions to pull out the result from the collection and store it in an output parameter.  You can see if if you download the UDA below and import it into your Nintex Workflow environment. 

Conclusion

You can nowuse the shortened URL to tweet, post on Facebook, Yammer, LinkedIn or use it in email.

The one thing to remember, is that in order for this work, your SharePoint environment needs to be exposed to the internet in order for the Web Request to to.ly to work.

Downloads

Nintex Workflow 2010 – v2.3.9.0

Shorten URLĀ UDA – Download

Leave a Reply

Your email address will not be published. Required fields are marked *