Return first item from array for subitems of array
Options
Anna Sho
Member ✭
Hello, Xano! I need help for noobs 🙂
I have a table of products and in API call each product contains a list of photos.
[
{
id: 2,
name: name,
photos: [
{url},
{url}
…
]
I want to have only 1 photo (first element of photo array can have ID 0, or 1 if 0 was deleted) instead of list of photos [array] in response of this API call.
How to do this?
Thanks in advance!
I have a table of products and in API call each product contains a list of photos.
[
{
id: 2,
name: name,
photos: [
{url},
{url}
…
]
I want to have only 1 photo (first element of photo array can have ID 0, or 1 if 0 was deleted) instead of list of photos [array] in response of this API call.
How to do this?
Thanks in advance!
Comments
-
Hi, so at the point where you are mapping the photo to your Add Record function, you would have to select a "Filter", specifically called "first"
This filter gets the first entry of an array.
- Please do confirm if this is correct
[Screen Shot 2022-06-09 at 13.04.36 PM.png] -
Looks good, thank you Umair!
-
Thanx, I'll try!
-
sorry for asking again. It seems for me too complicated since Im total noob)
I need that function for response of GET API call not POST, table itself shouldnt be changed, I need to display list of products with 1 photo only in schema not array of photos (issue in my frontend Draftbit) and I can reuse that function for other tables too..
if you have such awesome screenshot for my case that would be great! -
Hi, Anna. You should still be able to apply the same principle above on a GET request.
-
but instead ADD Record from Products there should be GET record right?
-
I understand now, thanks for clarifying. For this, you could create a variable using dot notation (which would allow you to basically select the first image in the array).
In this example, I have a table called 'deal', with an image object as a list. If I query the entire record, I get all three images I have stored in that one record. But, if I get the record, and then create a variable to extract only the first image, using dot notation, like this[image.png]"deal" - the table
"images" - the object storing the images
"0" - getting the first image in the list
"url" - getting the URL of the image
[image.png] -
Awesome! I'll try!
-
The problem in my case is that the initial GET request is too large, if I pull in all the list items my function is far too slow - anyone know of a way to just grab the first event initially? I guess a work-around could be to run a task every day that grabs the first item in this list and sets it to another field, but seems like a hefty solution to a simple problem
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback