Uber Price Estimate UDA

Blog Post created by Employee on Jan 10, 2015

Continuing from my previous post on Latitude and Longitude UDA, the process that I was discussing this week was around a company whose employees would go on business trips and they would stay at a hotel.  What they want, was to automate a process that at a particular time of the day, a notification would be sent out to their employee with information on how much it would cost them to get an Uber ride from the hotel they are at and also the duration of the ride to the airport they need to go to.





In order to get that information from Uber, you will need to have an Uber account.  You will also need get an Uber Server Token, which is what will be used to send the requests to Uber.


To get the API Server Token, go to the Uber API page, and register an app.  This will give your server token that you will use.


How does it work?


Firstly, there is the URL we will need to build, and we can do that with a Build String action.


As you can see, it takes 4 parameters, the Start Latitude and Longitude and the End Latitude and Longitude.  That's where my previous post comes into play.


This is not all that is needed.  The result that comes back from Uber is in JSON form.  There's no JSON parser in Nintex Workflow (yet!!).  So I had to be a little creative.  I'm not going to go through all the details of how the UDA works.  Suffice it to say, we take the JSON data, extra data out of it and store it in a collection.  Once we have that, we can iterate through the data and pull out the data we need.


I've wrapped this into a User Defined Action, because again, it's reusable in other workflows and it also makes it easier to share here.


The UDA takes a number of Input and Output parameters.


We have the To and From positions and also an Uber Class.  That is the type of car you're interested in.  In these, the customer was looking at the uberX car.


The output parameters, are a duration (in minutes) and a price estimate.



You can see from the Web Request action, that we've put in the Url we built up with the Build String action, we've also added a header.  This header, Authorization, is where you add your Uber Server Token.  Make sure that before that, you have the "Token " text also.


For those that are interested, to pull out the Name/Value pairs of data from the JSON response, I used the following Regular Expression:




Pretty right?  I actually found it online and had to tweak it a little.


Here is a screenshot of the UDA design.  I zoomed out a lot, so you probably won't see the details.  But you'll be able to download it and import it into your environment.


There a few smarts in this, in that it iterates through the results, but once the Uber class is found, it stops the For Each loop. So if you're interested in how that is done, I suggest you look into that.




As with my previous post, I suggest you make this a little more robust and capture the HTTP status and handle it, and also enable the error handling, just incase.


I've attached the UDA to this post, which you need to import into the new User Defined Action designer page.  Once that is done, I've also attached a workflow to this post, which uses both the Latitude and Longitude UDA and the Uber Price Estimate UDA.



As you can see in the screenshot of the workflow above, we have two calls to the Get Latitude Longitude UDA.  This is because we need a To and From position.  We use a Set a Condition to make sure we have both latitudes and longitudes.  If we do, we then use the Uber Estimate UDA.  Now that we have the information we need, we can use it in a Send Notification action, to notify our employee.  This gives them an idea of the price for the ride to the airport and also the time it should take.  That way, they can make sure they don't miss their flight.


In the UDA in this post, I stored my Uber Server Token in a Nintex Workflow Constant.  You will need to modify the Web Request action to make sure you use your server token.


Don't have Nintex Workflow and want to try it?  Download the trial here.