Part 1-My First Successful API Callout
I'm learning about HTTP Callouts, and wanted to share what I've figured out so far. My goal was to use API to update a contact record based on the contact's zip code. This is a beta feature that's available in all sandboxes and orgs that have "rolled forward" to spring '23.
I started with an API called Zippoptam.us. Here's how the API works: if you write a zip code in the URL, it will send you information about that zip code. For example: http://api.zippopotam.us/us/20011 gives you this:
Next, I created an invocable action. I wrote "/US/{ZIP}". This mirrors the format of the url I showed above--the zip in the curly brackets shows the value that I want to set based on the value of an account field. Once I typed in the url, the "Key" ZIP appeared below. I set ZIP as string because a zip code is a text string.
My next step was to click on the sample response button and add a sample. To get the sample response, I went back to by browser (firefox) and selected raw data. Then I copied the text below.
And
I pasted it to Sample Response. Note that it shows the information
that I get back (after clicking review). Note that it lists the data "type" of the responses. I was right when I guessed that zip code (aka post code) is a string:
Now, I select the action that I made in the flow and set $record.MailingPostalCode as the source for zip (the key I created above). My flow, by the way, is a scheduled flow that runs on contact records where the zip is not null:
After
debugging the flow, you can see it got information about 20011 (I could
have picked another zip code, but I wasn't creative)
Sadly,
I was not able to pull all of this data into my flow (most notably, I
wasn't able to get the state). When I created an update record element, I was able to select the outputs:
But only these were available.
Thankfully, I was able to select country and use it to update the contry field on the contact that triggered the flow.
It proves that I "did the thing," but isn't practically useful in this case. I, after all knew that all the inputs were going to be from the us, because I'd selected: http://api.zippopotam.us/us/ as my url of choice.
I was hoping to access the state or city, but they are part of an array, basically a list of strings. I know that you can use apex to access items within the array, but given that I'm hoping not to use apex, this isn't what I'm hoping for. At the very least, it means I have the wrong API if I want to really use this flow with my current skill level.
As a bonus thought, it looks like you can access the array in the update record item (even if clicking in the value box suggests otherwise). When I added ".places" (the name of the method that the array is associated with) as shown below and assign it to MailingCity:

Comments
Post a Comment