The corner-stone of the industrial revolution was the ability to automate the boring tasks. Also, this hold good during the era of digital data revolution. While exploring and analyzing vast datasets can be very rewarding, a fair bit of this involves repetitive tasks. It could range anything from looking for that single ‘whitespace’ in an unstructured dataset to downloading data from a web on a day-by-day basis.
While there is no ‘one size fits all’ solution for this problem, Alteryx makes dealing with such tasks easier. One of the famous used features for handling repetitive tasks is Batch Macros.
The below example how data can be downloaded with a relatively simple macro. The data in this example is downloaded from ‘https://data.police.uk/docs/’ website using an API.
The highlighted part shows the date component of the dataset. Under normal working conditions, a single date entry grabs a single set of data for only this date. Using Batch Macros, datasets for
multiple dates can be downloaded.
Part 1: CREATING BATCH MACROS
Step 1: Create a text input with the above mentioned URL as a record. The date parameter can be changed per convenience. In this case it’s ‘DT’.
Step 2: Go to ‘Interface’ tab and drag the ‘Control Parameter’ tool to the flow. Upon doing this, a small ‘Lightning’ Icon appears over the Text Input tool.
Step 3: Upon Connecting the Control Parameter to the Text Input, an ‘Action Icon’ appears. Clicking on this opens a new configuration window requesting an ‘Action Type’.
Under the Action Type Selection dropdown, select – ‘Update Value’. Choose the URL value. This the value from the Text Input.
Step 4: At the very bottom of the configuration window select ‘Replace a specific sting’. Then, choose the string. ‘DT’ in this case.
Step 5: Drag ‘Macro Output’ tool to the flow.
Step 6: Save this macro at a desired location. Give it a relevant name.
Part 2: USING BATCH MACROS
Step 1: In a new Workflow, create a text input. This input has a field with a list of dates in the required format. ‘YYYY-MM’ in this example. These date values replace the ‘DT’ in Part 1.
Step 2: Search for your saved macro and drag it into the workflow. In the configuration window, select the ‘Date(String)’ option from the dropdown. This is the input to the Batch Macro.
Step 3: To this, connect the Download and JSON Parse tools. In the JSON Field dropdown select the ‘DownloadData’ field.
Step 4: Upon running this flow, an API request is sent to the data.police.uk server for each of ‘Date’ values.
So there you have it. A brief tutorial on how to automate API requests using Batch Macros.