strapi

Unable to findOne record by ID (404 not found) while it can find ALL records of the sample data in Strapi 5


I newly installed the Strapi using the command below and chose to create the sample data.

yarn create strapi

I published all the articles and double-checked both find and findOne permission has been granted to the Public role on Author data.

I used Google Chrome to query the Author records.

I can get ALL the Authors records through this URL: http://localhost:1337/api/authors

    {
        "data": [
            {
                "id": 1,
                "documentId": "j32zwfrmo0h7ed5fk51qb1is",
                "name": "David Doe",
                "email": "daviddoe@strapi.io",
                "createdAt": "2024-10-03T14:54:43.775Z",
                "updatedAt": "2024-10-03T14:54:43.775Z",
                "publishedAt": "2024-10-03T14:54:43.772Z",
                "locale": null
            },
            {
                "id": 2,
                "documentId": "d7tjdbzbakg83kgnxe7818fi",
                "name": "Sarah Baker",
                "email": "sarahbaker@strapi.io",
                "createdAt": "2024-10-03T14:54:44.657Z",
                "updatedAt": "2024-10-03T14:54:44.657Z",
                "publishedAt": "2024-10-03T14:54:44.652Z",
                "locale": null
            }
        ],
        "meta": {
            "pagination": {
                "page": 1,
                "pageSize": 25,
                "pageCount": 1,
                "total": 2
            }
        }
    }

However, I cannot get the any individual record from URL below and it throws 404 not found error.

http://localhost:1337/api/authors/2

{
    "data": null,
    "error": {
        "status": 404,
        "name": "NotFoundError",
        "message": "Not Found",
        "details": {}
    }
}

I have no customization to this Author collection type.

The controller of the Gift collection ./src/api/author/controllers/author.ts is as below:

/**
 *  author controller
 */

import { factories } from '@strapi/strapi';

export default factories.createCoreController('api::author.author');

did I miss any step?


Solution

  • Try using the documentId prop value instead of id.

    http://localhost:1337/api/authors/d7tjdbzbakg83kgnxe7818fi in your case.