#soma-search-product

1 messages · Page 1 of 1 (latest)

fast sail
#

Hey @pale oasis

#

Let's say you have 3 products, prod_A, prod_B and prod_C (most recent)

#

when you search the first page will return prod_C (most recent). If you ask for the next page you say "hey give me the products after prod_C" so we return prod_B, etc.

#

Now if you search and get prod_C and you use ending_before, then you get nothing since there's nothing more recent than prod_C

#

Does that make sense?

pale oasis
#

consider this scenario

#

product a, product b and product c

fast sail
#

I mean just stick with my scenario 😅

pale oasis
#

suppose limit = 1

#

first call it returns has_more = true, and next_page=wwwww

#

call the endpoint again passing limit=1 and page=wwwww

#

it will return has_more = true and next_page=bbbbb

#

if I call the endpoint with limit=1 and page=wwwww (going back) then it will return has_more = false, and next_page=null

#

see what I mean?

#

it looks like a tonge twister

fast sail
#

what do you mean by "going back" in your sentence?

pale oasis
#

the pagination can move forward and backward

#

the thing is:

#

in the 3rd page of the pagination the next_page will be null and the has_more will be false

#

but if I want to go from the 3rd page to the 2nd

#

I can not receive a false data

fast sail
#

Do you have some code? I'm sorry I am not following you at all

pale oasis
#

ok, I will try to rephrase

#

I have 100 products

#

I want to get them 10 by 10

#

so far so good?

#

first call to the search will return the very first 10 items and has_more as true and the next_page as 'asdksjdsalkdjsadk'

#

second call will have limit=10 and page='asdksjdsalkdjsadk', it is supossed to return 2nd page

#

right?

fast sail
#

yes

#

I'm still really confused by your words, so sticking with my example.

1/ I call the search API and I get prod_A + next_page: 'aaa'
2/ I call the search API with page: 'aaa' and I get prod_B + next_page: 'bbb'
3/ I call the search API with page: 'bbb' and I get prod_C + next_page: 'ccc'
4/ I call the search API with page: 'aaa' and I get prod_B + next_page: 'bbb' (same as the example in #2)

#

with that concrete example, what part is not working for you?

pale oasis
#

the 4th

fast sail
#

Cool so that works totally fine for me with real code. Can you share real code that I can use to reproduce?

pale oasis
#

I can't sorry

#

my code is spreaded into my react component

#

oh, sorry, maybe this could help

#

using nodejs and express

#

return await stripe.products.search(params);

fast sail
#

I have written end to end code paginating and clearly trying multiple pages. So I'm going to need a bit more from you than this to be able to help you

#

Can you give me a simple end-to-end code reproducing the exact issue? Because right now it looks more like a misunderstanding

pale oasis
#

you know what? I will try this again from scratch

fast sail
#

Yeah that might help, I wonder if you're mixing up the page ids during attempts

#
  'query' => 'active:\'true\'',
  'limit' => 1,
]);
$nextPage1 = $products->next_page;
stripeDump($products);

$products2 = $stripe->products->search([
  'query' => 'active:\'true\'',
  'limit' => 1,
  'page' => $nextPage1,
]);
$nextPage2 = $products2->next_page;
stripeDump($products2);

$products3 = $stripe->products->search([
  'query' => 'active:\'true\'',
  'limit' => 1,
  'page' => $nextPage2,
]);
$nextPage3 = $products3->next_page;
stripeDump($products3);

$products4 = $stripe->products->search([
  'query' => 'active:\'true\'',
  'limit' => 1,
  'page' => $nextPage1,
]);
stripeDump($products4);```
#

that's my basic PHP example

pale oasis
#

thanks

fast sail
#

keep me posted!

pale oasis
#

you were right, it workds

fast sail
#

phew

#

Thanks for taking the time to test, I was worried for a minute, since it's a new "pattern" of pagination