Hi,
I need to geocode addresses to generate lat, long, and Congressional District data.
I do not have a use case for the Alteryx add-on, so I am using geocod.io and their API.
I can successfully construct the URL and use the Download tool to run Single Addresses queries.
I would like to figure out how to use Alteryx to run a Batch using their own simple sample data in a JSON Array.
[
"1109 N Highland St, Arlington VA",
"525 University Ave, Toronto, ON, Canada",
"4410 S Highway 17 92, Casselberry FL",
"15000 NE 24th Street, Redmond WA",
"17015 Walnut Grove Drive, Morgan Hill CA"
]
I am cluelss as to how to configure the Alteryx Download tool to generate a result.
The API instructions for Batch Geocoding can be found under the heading Geoclding here....
I have zero experience working with APIs, so its all Greek to me.
I have included a sample JSON array from the Geocod.io API Batch Geocoding example to keep it simple. Get this to work, and I am sure I can sort out real world data.
Thanks
Solved! Go to Solution.
Hi @hellyars
Let's break down what their example code snippet means
curl -X POST \
-H "Content-Type: application/json" \
-d '["1109 N Highland St, Arlington VA", "525 University Ave, Toronto, ON, Canada", "4410 S Highway 17 92, Casselberry FL", "15000 NE 24th Street, Redmond WA", "17015 Walnut Grove Drive, Morgan Hill CA"]' \
https://api.geocod.io/v1.7/geocode?api_key=YOUR_API_KEY
The actual URL endpoint that you want to hit is this: https://api.geocod.io/v1.7/geocode?api_key=YOUR_API_KEY
You will want to use a Text Input tool in the very beginning of your workflow where you paste this URL in. Make sure to swap out the YOUR_API_KEY with your actual API key value. You shouldn't need quotes around it, just put it in as it is at the end of the URL. The Download tool you will want to make sure that the "Basic" tab points to this URL. The other settings in the "Basic" tab should be good as is.
The first line indicates that this is a POST request so we will want to make sure that the HTTP action is set to POST in the Payload:
The second piece you want to look at is what comes after the -H which indicates that they are headers. You can hard code the Name and Value into the headers tab as seen below.
Aside from that, I would first recommend trying your sample JSON snippet in the Query String/Body before trying to make anything more dynamic. You would paste the JSON in here:
Once you confirm that this approach works, you can then work on dynamically pulling in this query that you can build in your workflow and use the option above to "Take Query String/Body from Field".
I think that this should get you pointed in the right direction, but let me know if you get stuck. The response from the API call will come in the "Download Data" cell after the Download tool. The response will also be in JSON so you will want to follow the Download tool with a JSON Parse tool, then a text to columns splitting on the period delimiter, then crosstab the data into the tabular format that you expect.
@BrandonB Thank you. This is exactly what I needed. Now I know what to do and why to do it. The attached workflow transmits the query and receives, parses, and cleans the results.
Create the JSON array from the address field dynamically - then set Payload to Take Query/String/Body from Field.
Step 1. Start with an Address field that contains all the addresses you want to run in the batch.
Step 2. Use a Formula Tool to add a quote at the front and beginning of each Address record. '"'+[Address]+'"' (aka Field1 in my screenshots)
Step 3. Use a Summarize Tool to Concatenate the Address field. Set Start to [ Set Separator to , Set End to ].
Step 4. In my workflow I append the Concatenated Address field to the URL field. See first image above.
Step 5. Set Payload to Take Query String/Body/ from Field = Address
Excellent work @hellyars !