Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

CS Macro Dev: Deploying API Calls in Macros

MattD
Alteryx Alumni (Retired)
Created

This article is part of the CS Macro Development Series. The goal of this series is to communicate tips, tricks, and the thought process that goes into developing good, dynamic macros.

Implementing APIs into macros isn’t a difficult process, you only need to first understand macros and how they’ll interact with your API requests. In short, a macro gives you the ability to encapsulate just about any repeatable process in an Alteryx workflow as a tool. Understanding that, you only need to identify what in your API request will need to change with each row the process/request is being repeated for, and how to update this request dynamically.


With each row of your input data stream, expect to be able to use fields to reference what individual values will be – doing soin a formula tool willbuild out parts of the request that change with each record. If instead you need to update an argument of the request just once for all your records, try using an interface tool and a place-holding value. Need to update parts of a request for only certain records? You can use formula logic or the batch macro’s control parameter approach.

Consider the Google Maps Geocoding API request format below:

1.png

If we were to send a request to their API to geocode a single address (specifying an xml output), this would look like:


https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+C...


To update this dynamically, within a macro, we need only to map our input fields to their appropriate places in the request, emulating the rest of the request syntax with formula logic:


"https://maps.googleapis.com/maps/api/geocode/xml?"+"address="+replace([Address]," ","+")+"+"+[City]+"+"+[State]+"+"+[Zip]+"&key="+"X"

(the replace function exchanges spaces for + characters, the remainder of the + characters are added as literal strings to mirror the format above)


Then only updating our key remains before passing this to a Download Tool, and this will be the same for all our input rows:

2.png

3.png

Thev10.5example above is attached for reference. It is an adaptation of a more robust Google Maps Geocoder hosted on our gallery.

Please note that in order to use this macro, you must first generate a server key from the Google Developers Console. Each key has a limit of 2,500 free requests per day.Click here for more information on usage limits for the Google Maps API.

This macro demonstrates requests to Google Maps' web service API and is meant as a proof of concept only. It is not intended for production use.

Attachments
Comments
BI_Pleb
7 - Meteor

really good, thanks