Having trouble using strapi populate plugin with custom route using UUID

System Information
  • Strapi Version: 4.4.5
  • Operating System: Windows 10
  • Database: postgres
  • Node Version: 16.18.0
  • NPM Version: 9.1.3
  • Yarn Version: 1.22.19

Hey, I have set some custom routes to use with the UUID strapi plugin, but I’m not being able to use them as my older routes that used strapi’s native IDs solution.

On my older routes with simple IDs I need the populate plugin to get some of the nested structures of my collections, but after I switched the simple IDs to the UUID plugin, I found out I had to create my custom routes to handle them, but I’m not being able to reproduce the same usage of populate plugin on my new routes with UUID.

I’m kind of new to the idea of customizing strapi backend routes and mixing plugins, so I don’t know much of what I should look for or start doing.

Here’s an example of one my current custom routes controller to get a collection by UUID


import { factories } from "@strapi/strapi";
const modelUid = "api::form-model.form-model";

export default factories.createCoreController(modelUid, ({ strapi }) => ({
  async findOne(ctx) {
    const { uid } = ctx.request.params;
    const { query } = ctx;

    const entity = await strapi.service(modelUid).findOne(
      {},
      {
        where: { uid },
        populate: query.populate,
      }
    );

    const sanitizedEntity = await this.sanitizeOutput(entity);

    return this.transformResponse(sanitizedEntity);
  },
}));

This is the custom.ts route I’ve created to get a collection by it’s UUID

export default {
  routes: [
    {
      method: "GET",
      path: "/form-models/:uid",
      handler: "form-model.findOne",
      config: {
        auth: false,
      },
    },
  ],
};

Can anyone give me a hand on what to do or where to go?


I have the same issue. Did you find a solution ? Best