I have created multiple collections and entries to those collection i want to fetch all entries in one API call is there any way i can do that
Hey @Kamlesh_Singh
Yes, you can achieve that in 1 API call by developing a custom API in any of the content type collection controller.
Below is an example on how to achieve that:
In /api/content-type/routes/content-type.js file:
{
method: 'POST',
path: '/your-api-name',
handler: 'api::collectionName.collectionName.fetchAllData',
}
and add the function inside /api/content-type/controllers/content-type.js file:
fetchAllData(): async (ctx) => {
const collection1 = await strapi.db.query('api::collection-1.collection-1').findMany();
const collection2 = await strapi.db.query('api::collection-2.collection-2').findMany();
ctx.send({
status: 200,
data: {
'collection1_data': collection1,
'collection2_data': collection2
}
})
}
Set permission of the custom API from roles and you are good to go for executing the custom api.
Hope this information helps you
Thanks
HI @Shekhar thanks for the reply. but in my case collections are not getting created by me(sorry for the miscommunication in the post) so I don’t know the collection name that the third person is going to create.
I have been using Contentful CMS for the past 2-3 days. and they have one global API that sends back the whole data of the collections that are being created inside one space. I want to get similar response