Nintex Workflow – Shorten URL 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 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.
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.
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:
To extract the shorturl, we can use a Regular Expression action, with this expression : (?<=”: “)[\w\W]+(?=”, “)
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.
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.