Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to prevent duplicate records with since_id in Node Rest Admin API

How to prevent duplicate records with since_id in Node Rest Admin API

DelfineUmaku
Visitor
2 0 3

I am building a Node REST API that makes calls to a list of Products. I am using the 'since_id' parameter to only retrieve new records that have been added since the last call. However, I am noticing that duplicate records are being returned in my list. Has anyone else encountered this issue and found a solution to prevent the duplicate records? Any help would be greatly appreciated, thank you.

  do {
    page = await shopify.api.rest.Product.all({
      session: session,
      limit: 50,
      since_id: page.length > 0 ? page[page.length - 1].id : undefined,
    });
    products = products.concat(page);
  } while (page.length > 0);

 

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1453 238 527

Hi @DelfineUmaku , This blog article here might be of some help to you https://www.shopify.com/partners/blog/relative-pagination. Perhaps including since_id=0 in the endpoint would help with this https://www.shopify.com/partners/blog/relative-pagination#:~:text=To%20ensure%20the%20first%20page%2... 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

laurensiusa
Shopify Partner
1 0 0

EDIT: "since_id=0" on the first page request solves the problem.

 

I'm experiencing the same. Basically what happen is, after certain page, the since_id becomes the same over and over, because page[page.length - 1].id returns the same ID, then we get the same results again.