API Endpoints in Strapi V4

Viewed 978

I'm new to Strapi and Following Strapi Tutorial Playlist in Youtube.Youtube Playlist is old and He is using Strapi V3. But Current Version is 4.0.5. I facing problem in using API Endpoint.

I created Collection type and named it as Posts.I even published it.When I navigate to http://localhost:1337/api/posts, It returns

{
  "data": null,
  "error": {
    "status": 403,
    "name": "ForbiddenError",
    "message": "Forbidden",
    "details": {}
  }
}

Does somebody help me please?

2 Answers

If you try to retrieve the data as a public user, then you need to go to roles and set the appropriate rights.

Settings -> Users & Permissions -> Roles -> Public -> Posts

then make sure find and fineone are checked.

For me, the problem was that I needed to set a scope for the auth configs of the route.

Like this (please note the scope):

  routes: [
    {
      method: 'GET',
      path: '/custom-route',
      handler: 'custom-controller.getCustomMethod',
      config: {
        policies: [],
        auth: {
          scope: ['find'],
        },
      },
    },
  ],
Related