Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query collections from custom plugin in strapi?

Tags:

plugins

strapi

I want to collect data from my collections and display it in my own plugin, for example 'Cars'. I have not found anything about this and do not know how to approach this.

import React, { memo } from 'react';
import pluginId from '../../pluginId';
 
const HomePage = () => {
  const fetchData = () => {
      // Here I want to fetch data from my collection and display it
      return null;
  }
 
  return (
    <div>
      <h1>{pluginId}&apos;s HomePage</h1>
      <p>Happy coding</p>
      {fetchData()}
    </div>
  );
};
 
export default memo(HomePage);
like image 881
Seajanjan Avatar asked Oct 30 '25 11:10

Seajanjan


1 Answers

Old question but I've been looking for the answer and it's difficult to find. So the solution for this, is to use the endpoints provided by the content-manager plugin of strapi.

First you should go and allow public access to this endpoints in Settings then Roles & Permissions plugin.

Finally you can query your data like this

const response = await request("/content-manager/collection-types/application::cars.cars", {
        method: "GET"
      });
}
like image 108
Martin Gaviola Avatar answered Nov 03 '25 00:11

Martin Gaviola



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!