Count number of entries in a model

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:

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

please can you remove this question because of api_key?
thanks

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

let’s keep it
thanks

1 Like