List records using CMA

Hi, I’m using this code to fetch records:

const allTrips = await client.items.all(
        { 'filter[type]': 'trip', locale: LOCALE },
	{ allPages: true }
);

My issue is that a fetch a lot of records (14k), and this requests fetches all the props inside every object. Is there a way to fetch just specific fields of the model (eg: ‘slug’ or ‘id’)? I’d like to do the same that I can do with GraphQL. Thank you!

Hello @julian1

Unfortunately due to the fundamental differences between REST and graphQL APIs this is only possible through the CDA, sorry.

1 Like

Thanks for replaying. So what do you recommend then? Because I’m using vercel to compile my static pages and it takes more than the allowed time due to the delay of that big request

1 Like

@julian1

It is kind of hard to recommend something because i don’t know your exact use case, but some general pointers would be:
If you’re not modifying the values of the fields , you should use the CDA.
If you only wish to modify some of the records of that 19k list, you should set up the appropriate filters to reduce the response to only the records you want to modify.
If you want to modify all of the 19k records, then doing it with pagination (not using allPages:true) would be the way to split the process into several smaller requests, avoiding running into that time limit.
But for that last case, it can lead to some future problems, as changing 19k records on every build, seems like something that would pile up a lot of CMA requests quite quickly, so this excess amount of requests would be something to keep in mind

Hope this helps!

1 Like

I just need to compile all my static pages, nothing more. But the CMA takes too long, and the CDA would use a lot of requests because it brings just 100 records per request.

@julian1

Unfortunately for this case the CMA won’t be a good fit, the CDA would indeed be the best option, even splitting it into several requests, due to the speed of the requests.
But if you are only doing it on build time and are looking to save up on requests, the CMA could be an option
You can read about this here: Content Delivery API - Overview - DatoCMS Docs

(edited to correct the information on CDA caching)

1 Like

Thanks for replying. But it’s not the same to cache de CMA response and de CDA’s?

1 Like

@julian1

We don’t have an internal cache for the CMA. But if you are focused on lowering the number of API requests, and you are doing this only on build time, you can still do it through the CMA, but instead of using allPages, maybe do a pagination of 500 records at a time? This way you can minimise the amount of requests and circumvent the Vercel timeout

1 Like