GET API request to display on the glide table

I’m gonna get the some date(correctly user location)
so, I have to send the GET request to the following URL
https://nominatim.openstreetmap.org/reverse?format=json&lat=51.165691&lon=10.451526&zoom=18&addressdetails=1

so, How to fix the this problem?

What type of column is fetchedLocation?
Can you show how that is configured?

Thank you for your reply…
I don’t know much about it. That’s my problem to solve.
could you please teach me how to fix this?

Well for starters:

1 Like

I think it’s custom code

OK, so you don’t have any javascript code yet.

Since your url does not require an API key, you can safely run this in javascript. If any private keys are involved, then I do not recommend this method because anybody could steal your key and use it for themselves.

Also, the javascript method does not provide suitable caching, so every user device will run this code for every row every time that app is opened. This could get a user rate limited if OSM has any restrictions in place.

The best way to run API calls like this is to use the CallAPI function in Glide because it runs server side and caches data, so you can safely use API keys and reduce any chances of being rate limited.

You being warned of the consequences of using a javascript column. With that said, here is javascript code that will do what you want. The URL should be passed as the p1 parameter.

async function getFormattedAddress(url) {
    try {
        const response = await fetch(url);
        const data = await response.json();

        if (!data.address) {
            throw new Error("Address data not found");
        }

        const address = data.address;
        const formattedAddress = `${address.road}
${address.city_district || ''}
${address.city}, ${address.county}
${address.state}, ${address.postcode}
${address.country}`;

        // Remove extra spaces or blank lines
        return formattedAddress.trim(); 
    } catch (error) {
        console.error("Error fetching or formatting address:", error);
        return null;
    }
}

if (p1) {
  return await getFormattedAddress(p1);
} else {
  return '';
}
1 Like

Thank you for your help!

1 Like

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