# Structuring Template for API call

**URL:** <https://community.glideapps.com/t/structuring-template-for-api-call/70131>\
**Category:** Ask for Help\
**Created:** [January 27, 2024, 6:10pm UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131 "2024-01-27T18:10:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryanb12](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ryanb12/32/64617_2.png) [@Ryanb12](https://community.glideapps.com/u/Ryanb12)\
**Post date:** [January 27, 2024, 6:10pm UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131/1 "2024-01-27T18:10:59Z")

</div>

Hi all, I need some help trying to figure out how to structure my dynamic search results into a template.

Basically the function is I have someone who searches for one or multiple cities in my app. Those results get put into a user specific text column. From there I need those dynamic results to basically fit into this format: City eq ‘CITY1’ City eq ‘CITY2’ City eq ‘CITY3’.

Currently my data is comma separated: Los Angeles,Anaheim,Claremont,Irvine

Reason being is this is how I need to structure the data for my api call. I’m having a hard time trying to wrap my head around how to structure this or what to use. I tried using GPT to create a javascript code that would take that text and convert it into the format I needed, disclaimer I don’t know how to code lol (Couldn’t get it to work) → Here is the code:

```auto
window.function = function (p1) {
  if (p1 && p1.value) {
    let cities = p1.value.split(',');

    if (cities.length === 1) {
      return `City eq '${cities[0]}'`;
    } else {
      return cities.map(city => `City eq '${city.trim()}'`).join(' or ');
    }
  } else {
    return undefined;
  }
}

```

Lastly, I did get it to work using the generate text feature but that is eating up more usage then I would like. I would prefer to get this done either using a computer column or javascript if possible. Any help is appreciated!

 ![Screenshot 2024-01-27 100903](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/2/124c5d49325044ad6bd66bab8d5e1e18ff60614b.png)  
 ![Screenshot 2024-01-27 100916](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/b/4b26a3c56ab8601e5a593bc7141b0a5e08afd1b2.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [January 27, 2024, 6:26pm UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131/2 "2024-01-27T18:26:13Z")

</div>

This is doable with 2 or 3 template columns if you want something easier to understand.

However try this javascript. I only modified yours slightly by pulling the code out of the function. You had a function, but you weren’t calling the function in your code. (disclaimer: didn’t test the code below)

```auto
 if (p1 && p1.value) {
    let cities = p1.value.split(',');

    if (cities.length === 1) {
      return `City eq '${cities[0]}'`;
    } else {
      return cities.map(city => `City eq '${city.trim()}'`).join(' or ');
    }
  } else {
    return undefined;
  }

```

---

<div class="post-metadata">

**Author:** ![Ryanb12](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ryanb12/32/64617_2.png) [@Ryanb12](https://community.glideapps.com/u/Ryanb12)\
**Post date:** [January 28, 2024, 1:25am UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131/3 "2024-01-28T01:25:07Z")

</div>

Hey Jeff thank you for your input. I gave it a try but got an unexpected string error.

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [January 28, 2024, 1:56am UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131/4 "2024-01-28T01:56:35Z")

</div>

OK, actually tested it this time and cleaned it up a little.

Try this:

```auto
if (p1) {
    let cities = p1.split(',');

    if (cities.length === 1) {
      return `City eq '${cities[0]}'`;
    } else {
      return cities.map(city => `City eq '${city.trim()}'`).join(' or ');
    }
}

```

---

<div class="post-metadata">

**Author:** ![Ryanb12](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ryanb12/32/64617_2.png) [@Ryanb12](https://community.glideapps.com/u/Ryanb12)\
**Post date:** [January 28, 2024, 2:00am UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131/5 "2024-01-28T02:00:54Z")

</div>

THANK YOU! Worked like a charm! I appreciate your time and help!!  
 ![Screenshot 2024-01-27 175942](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/4/f4fc1a2f7f44583736f4c1ffa6744d9c5fc8a84a.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [February 4, 2024, 2:01am UTC](https://community.glideapps.com/t/structuring-template-for-api-call/70131/6 "2024-02-04T02:01:10Z")

</div>

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