How to use a custom URLSegment in an HTTP Request Activity inside of a For Each Activity

Hello Everyone,

I am having an issue when I try to use a for each activity to iterate through an array of strings and use that specific item as the custom text url segment for an API call using the HTTP Request activity.

Here is what I have so far and what I’ve tried.

Cities = {“New York, NY”, “Los Angeles, CA”, “Boston, MA”, “Cleveland, OH”}

For Each item in Cities:

For some reason, it’s not letting me use address = item.ToString for the custom url segment that would replace the text (ex. “New York, NY”)

I have attached my workflow and any help would be greatly appreciated.

Thanks!

Here is another part of my workflow

Hi, if you write item.ToString in the wizard it will literally use the string ‘item.ToString’, just go in the properties panel and change it there to take the variable instead.

Hi, thanks for responding to me. I tried what you said and put it in the properties panel instead of the wizard but its still not accurately getting the names of the cities I want from item in the for each loop.

Could there be something I’m doing wrong?

The easiest way to check would be if you can share the workflow so I can take a look. If you can’t share it, maybe make some screenshots showing how you filled in the stuff from the properties panel.

It looks like the value of address is the literal string “item.ToString”

Show us where you’re assigning a value to address. I suspect you have done…

Assign address = “item.ToString”

…when it should be without quotes…

Assign address = item.ToString

@Bogdan_Eusebiu_Siritanu Okay, I have attached my workflow. Please let me know if it needs further clarification.
The only other package I used besides the default one, was WebAPI Activities

Here is the documentation for the API i’m using Position Stack API

Main.xaml (9.4 KB)
project.json (1.5 KB)

Got it working, the problem seems to be how URL segments work. Sadly I can’t say I am an expert on http request stuff, so I can only say they probably work a little bit different than what intuition tells me, if you really are need to know, I would have to research them a bit.

What needs changing are the following:
-delete the location from URL segments
-change the endpoint to this value: “http://api.positionstack.com/v1/forward?access_key=7dff9075ad9b5330a3f6050ca91fb45b&query=” + item.ToString + “&country=US&limit=1” (also, it seems country takes a 2 letter code not the whole name, so keep that in mind if you need to change it from US to something else)

If there’s anything else you need help feel free to ask. I will also attach the modified workflow here just in case.
Main.xaml (10.0 KB)

Thank you so much @Bogdan_Eusebiu_Siritanu! I appreciate you helping me to fix the Url Segment error.

If I wanted to save just the latitude, longitude for each item as outputs outisde of the for loop should I just use an assign activity?

My goal is to have a geocoordinate pair of latitude and longitude so that I can use these coordinates for a different weather api

I’m also running into an issue where the workflow works perfectly once and then when I run it again it will throw an error half way or almost at the end? I’m confused why its giving me an inconsistent error

Yes, if you wanted to save them for later use, you could declare a dictionary to map the location name to the coordinates returned from the request. Show us the error it throws so we can solve that too.

Thanks for all your help @Bogdan_Eusebiu_Siritanu. I ended up realizing that the API result I need would require me to pay for it and I’m not planning on doing that so I think I will switch to using a data scraping method instead of an API HTTP Request.

I appreciate you helping me understand URL Segments better! I have set up my workflow for my data scraping inputs, but I have a question regarding how I can use a counter or some other method in a For Each Activity when I’m trying to write from each data table with write range. I want to make sure i’m not overwriting the previous iteration of the for loops data.

Since it’s unrelated to my original question, is it proper etiquette to create a separate topic?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.