How to get topic details when fetching items?

Hey guys,

I’m using Node.js client to fetch the data in my backend application.

I would like to reduce the amount of API calls (if possible), but I’m having a hard time understanding how can I do so, or if that’s even possible.

For example, I’m fetching an item with some id, then I get a response like the following one:

Then, I have a list of topics, which I fetch with a query like:
LinkToImage: https://i.imgur.com/2CqizD3.png

Finally, I also have to fetch images/videos/audio files I have in this topics (and in the “coverImage” field):
LinkToImage: https://i.imgur.com/hUZK7Ju.png

Is there a way to fetch this information in just one API call (the current flow takes ~6-7 seconds to fetch all the data), or if not, what are the alternatives I could/should use (e.g. Axios library and construct my own GraphQL calls)?

Looking forward to your reply!

Mauro

Hello @benec

I think what you are looking for is the “nested” parameter
By setting:

nested: 'true',

Your search will return the records themselves in the expanded form, not just their ID

Is that what you were looking for?

Hey @m.finamor, thanks for the quick reply!

Yes, this is what I’m looking for, but I tried query like this one:

But, I’m still getting a response like:

Any ideas on how to resolve this?

Thanks in advance! :slight_smile:

Hello @benec

So, this doesn’t work because the topicList array is an array for Refrences to other records, so the only way to get that entire record, is to loop through the array with a request per record ID.

A better way to design this instead, would be to make so that the topicList, is not a Multiple Links field, but a Modular Field (Or a Structured Text Field) instead. And make the topics, instead of new records as they currently are, new blocks, that can be referenced in the Modular Field.

This way the editing for your articles will become much more simple and streamlined, and you also get the added benefits of having less records, and you will be able to use the nested: 'true' approach i mentioned to get the entire information about the record.

Hope this helps!

Hey @m.finamor

Thanks for your reply. It’s a little bit clearer now how things are working, so now we should be able to find the solution for our problem internally.

Best regards,

Mauro

Hey @m.finamor

First off - thanks for the suggestion. We improved our structure and now indeed I can fetch nested objects, however, I have another question in order to improve the general performance.

Is it possible to fetch uploaded files URLs as part of the items.all query?

For example, this:

Results in:

So I’m wondering if it would be possible to get URL’s as a part of the same API call so I don’t have to call client.uploads API?

Thanks in advance,

Kind regards,

Mauro

Hello @benec

For this, i think using the CDA would be better.
Would doing a graphQL query inside NodeJS be possible for your use case?
This way you could get all records with all the parameters you would like.

Otherwise the only other way would be to access the URLS is through client.uploads

Hey @m.finamor

Thanks for the explanation.
GraphQL should be fine as well, so I’ll switch to the Content Delivery API then.

Thanks again - really appreciate your quick responses!

Kind regards,

Mauro

1 Like