# How can I get all object at a certain location?

**URL:** <https://developer.squareup.com/forums/t/how-can-i-get-all-object-at-a-certain-location/1955>\
**Category:** Questions\
**Tags:** catalog-api, ruby-sdk\
**Created:** [February 26, 2021, 6:09am UTC](https://developer.squareup.com/forums/t/how-can-i-get-all-object-at-a-certain-location/1955 "2021-02-26T06:09:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasunao\_izawa](https://avatars.discourse-cdn.com/v4/letter/y/c77e96/32.png) [@yasunao\_izawa](https://developer.squareup.com/forums/u/yasunao_izawa)\
**Post date:** [February 26, 2021, 6:09am UTC](https://developer.squareup.com/forums/t/how-can-i-get-all-object-at-a-certain-location/1955/1 "2021-02-26T06:09:22Z")

</div>

The number of items I have is under 200.  
But, if the code like below is executed,  
variable: items would be huge number（≒endless loop）,  
and ,items are overlapped many times.  
That array involve multiple :version of catalog\_objects.  
How can I get uniq and all item objects?  
Please,help me.

(It suppose that the variables:client. location\_id have been declered)

```auto
items=[]
cursor=nil
loop do
  result = client.catalog.search_catalog_items(
     body: {
        enabled_location_ids: [location_id],
        cursor: cursor,
        sort_order: "ASC",
        product_types: ["REGULAR"]
     }
  )
  if result.success?
     items.concat(result.body.items)
     break if result.cursor.nil?
     cursor = result.cursor
  elsif result.error?
     raise result.errors
  end
end

```

---

<div class="post-metadata">

**Author:** ![sjosey](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/sjosey/32/40_2.png) [@sjosey](https://developer.squareup.com/forums/u/sjosey)\
**Post date:** [February 26, 2021, 4:57pm UTC](https://developer.squareup.com/forums/t/how-can-i-get-all-object-at-a-certain-location/1955/2 "2021-02-26T16:57:05Z")

</div>

Hi @yasunao_izawa welcome to the forums!

In the Ruby SDK, `cursor` will be returned as an empty string, instead of nil. From the docs:

> - Make sure you get all items returned in a list call by checking the cursor value returned in the API response. When you call a list API the first time, set the cursor to an empty String or omit it from the API request. If the API response contains a cursor with a value, you call the API again to get the next page of items and continue to call that API again until the cursor is an empty String.

So, you can change `break if result.cursor.nil?` to `break if result.cursor.empty?` and that should end the loop correctly.

---

<div class="post-metadata">

**Author:** ![yasunao\_izawa](https://avatars.discourse-cdn.com/v4/letter/y/c77e96/32.png) [@yasunao\_izawa](https://developer.squareup.com/forums/u/yasunao_izawa)\
**Post date:** [February 27, 2021, 12:40am UTC](https://developer.squareup.com/forums/t/how-can-i-get-all-object-at-a-certain-location/1955/3 "2021-02-27T00:40:29Z")

</div>

Thank you for replying.  
I tryed this, then I can solved problem!
