[IN PROGRESS] Integrate Anaplan with Siri and IOS Shortcuts
We now live in a connected world and Anaplan provides us with connected planning but what about extending that connectivity even further. We carry in our pockets everyday our mobile phones that are amazing in the possibilities they offer to our lives. Anaplan has a great mobile app so that you can review your dashboards and input forecasts from wherever you are but how about extending that connectivity to exact times, your location or even running Anaplan via your voice.
Apple have an awesome app that will be installed by default on your iphone/ipad called Shortcuts.
With Shortcuts you can create powerful "If Then Do" logic that can either be automated or run manually.
A common example would be to create a Shortcut to automatically switch the lights on when you arrive home at night.
I was thinking to myself recently it would be amazing to extend this ability across Anaplan.
Imagine creating a Shortcut that would:
run an Anaplan process at a specified time each day and then logged the result to your Notes or Email
run an Anaplan process when you reached a specific location i.e. your office
logged the status of your models each morning to a file on Dropbox
Allowed you to run an Anaplan Process by just asking Siri
So I set about looking further into Shortcuts and found the secret sauce.
Anaplan has a very strong API having been designed for the cloud. You can review all the documentation here:
Having a strong API means that we can easily create POST and GET commands to interact with Anaplan.
Within IOS Shortcuts there is then a command called "Get Contents of URL" that allows you to execute the POST/GET etc.
So let's walk through an example of how to build:
a Shortcut that authenticates with Anaplan
Retrieves the Processes within a Workspace/Model
Executes a Process
Is then automated at any time or location
In the below screenshot you can see I have a number of Shortcuts. Some were downloaded from the galley and some were developed from scratch by me.
Let's start with how I built the "Anaplan Processes" Shortcut to return the processes within a model as I need the ID of a Process in order to run it.
In order to authenticate with Anaplan I did the following:
Use a Text command (found under Documents) to hold my Username:Password (it has to be in this format and be careful not to have any line breaks)
Insert a Scripting command to do a "Base64 Encode"
Set a variable to be the output of the Base64 Encode so I can re-use it elsewhere in my Shortcut
N.B. Authentication here is based on basic authentication and will then need to be amended every 3 months with the new password. Using a certificate would help to make this auth process more secure and less prone to code amendments.
If we now use a "Get Contents from URL" command we can use the URL in the "Get Contents of" field
Ensure the Method is set to POST
Add one header with Authorization as the key and the value being Basic and then the name of your variable output from the Base64 Encode. Be sure to leave a space between Basic and your variable i.e. Basic vUserPass
If you were to play this Shortcut at this stage you should reveive hopefully a successful authtication result. what we want though is out of the JSON message, we need text from the tokenValue, in order to use this Token when making further API calls.
In Shortcuts you can use a Dictionary to store or retrieve data in a Key:Value format similar to JSON. So if we use a "Get Dictionary Value" command we can retrieve the Value for tokenInfo.tokenValue
We use tokenInfo.tokenValue as it represents the path to that value within the JSON
Now we have the authentication in place we can now run a request to get a list of processes within a workspace/model. We need this as a way to find the ID of the Process we want to execute anyway. In order to get a list of Processes we:
I have included Set Variable command to retrieve the output of the Dictionary value that contains our tokenValue
Adding a "Get Contents of URL" command we can now reference the URL, ensure the method is set to GET and then add two headers
Authorization with a value of AnaplanAuthToken then a space and then our token variable
Content-Type with a value of application/json
You will now be able to run this shortcut by pressing the play button in the bottom right. On finish you should see a successful JSON return message consisting of all the Processes, their names and their IDs. Make note of the ID of the Process you want to execute. If you need to debug your shortcut you can add Show Notification commands or even create an IOS Note of outputs to analyse.
Let's leave this Shortcut in place working and copy it, so we can reuse the majority of the Shortcut but edit it slightly to execute Process instead of listing Processes. To copy a shortcut, just hold your finger down on the shortcut until a menu appears and select Duplicate.
The edits required on the shortcut to execute a process are:
N.B. The way the IDs are retrieved currently means that if IDs change you update the urls called by their codes. A way to address that point would be to add a step that will look for all IDs based on the name, using the endpoint "/models".
Now you have a working shortcut you can execute it at anytime by just pressing the shortcut. If you want to automate it though you go onto the next screen "Automation". Here you can create a new automation from the + menu item and select "Create Personal Automation" with an Event "Time of Day" and a Do of Run Shortcut and then just select your shortcut. You can change the timing to be any day/time or even sunrise/sunset.
The shortcut could be enhanced further by retrieving the outcome of the process (did it fail ? How many records are rejected?) and then notifying the user the outcome of the process.
Now you have created an automation with Anaplan, imagine now extending it to run an Anaplan process based upon you geo location, arriving at your office, a change in the weather or maybe a change in the exchange rate. Of course the coolest thing now is you can execute the Anaplan Process just by talking. Just say "Hey Siri, run the shortcut Anaplan Run Process". That will certainly surprise people in your next meeting.