# Count number of entries in a model

**URL:** <https://forum.builder.io/t/count-number-of-entries-in-a-model/6004>\
**Category:** Technical Questions\
**Created:** [July 15, 2024, 10:27am UTC](https://forum.builder.io/t/count-number-of-entries-in-a-model/6004 "2024-07-15T10:27:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shintaro](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Shintaro](https://forum.builder.io/u/Shintaro)\
**Post date:** [July 15, 2024, 10:27am UTC](https://forum.builder.io/t/count-number-of-entries-in-a-model/6004/1 "2024-07-15T10:27:28Z")

</div>

Hi there, I’m trying to optimize my code, because currently, I have a request to get all entries of a model and then return the data.results.length

Is there a way to request only to get the count given a field?

this is my current code:

```auto
const getCategoryCountApi = async (categoryKey: CategoryId) => {
    const params = {
      apiKey: $runtimeConfig.public.BUILDER_IO_MARKTPLATZ_API_KEY,
      "query.data.categories.category.$in": [categoryKey],
      limit: 1000,
      "query.published": "published",
    }
    const response = await axiosClient.get(`${$runtimeConfig.public.BUILDER_IO_ENDPOINT_URL}/marktplatz-offers`, { params })

    if (response && response.data && response.data.results) {
      return response.data.results.length
    }
    return 0
  }

```

API\_KEY =

thanks

---

<div class="post-metadata">

**Author:** ![Shintaro](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Shintaro](https://forum.builder.io/u/Shintaro)\
**Post date:** [July 18, 2024, 8:17am UTC](https://forum.builder.io/t/count-number-of-entries-in-a-model/6004/2 "2024-07-18T08:17:21Z")

</div>

please can you remove this question because of api\_key?  
thanks

---

<div class="post-metadata">

**Author:** ![Stephane](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Stephane](https://forum.builder.io/u/Stephane)\
**Post date:** [July 18, 2024, 8:22am UTC](https://forum.builder.io/t/count-number-of-entries-in-a-model/6004/3 "2024-07-18T08:22:03Z")

</div>

Sure, Carlos - I have removed the API reference and kept the question if that works for you.

Otherwise, I can remove it all completely if you want.

Thanks

---

<div class="post-metadata">

**Author:** ![Shintaro](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Shintaro](https://forum.builder.io/u/Shintaro)\
**Post date:** [July 18, 2024, 8:34am UTC](https://forum.builder.io/t/count-number-of-entries-in-a-model/6004/4 "2024-07-18T08:34:05Z")

</div>

let’s keep it  
thanks
