Create custom route


I trying to override the user creation route.
I want to use my api to create the user.
I have managed to throw an error if something goes wrong by tweaking the user file in the route folder.
But I didn’t find a way to tell forest admin that everything went right and that it doesn’t need to create a user since I’ve already done it (sending a request with status 200 triggers an error).
Is it possible to do it ?

Thank you for your help,

Hello @Ilias_El-mhamdi,

I am not sure to understand what you mean by “creating the user” yourself. Could you please elaborate? Maybe sharing the modifications you made to the user file would help.

Thank you


It was for my category table.
Here is what I’am trying to do.


// Create a Category
  async (request, response, next) => {
    // Learn what this route does here:
    console.log("create category");
    const categoryData =;
    let departementId;
    try {
      departementId =;
    } catch (err) {}
    console.log(departementId, "dep id");
    let categoryToCreate = {
      departmentId: departementId,
    try {
      //creating the category using my backend api 
      let res = await network.createCategory(categoryTocreate);
    } catch (err) {
      //error during the creation 
      response.status(500).send("can't create category");
      return null;
    //telling forest that the creation was successful 
    response.status(200).send("category created");
    return null;

Tell me if it’s not clear or if you need more infos
Thank you for your help and fast reply



Could you try to replace the end of you function by just

   response.status(200).send("category created");

If you compare you code with our documentation. The return and next statements are not required.

Do you have an error message to share?

I think you should also use the res value as a parameter to response.send to share the created record with your admin panel. It may need some data transformation to have the expected format.

Thank you for your help.
It’s starting work when I give res as then send parameter. I have the notification creation success but I still get an error.

It may be because my res Json dosesn’t have enough info, I just have the id of the created category. And I see that in the documentation :
.then(recordSerialized => response.send(recordSerialized))
What info should be in the recordSerialized, the problem might lie there.

Thank you,

This might add some processing delay, but you can try using the RecordGetter. See this: Smart field reference link

The process can be similar to:

  1. call await network.createCategory(categoryTocreate);
  2. call const record = await recordGetter.get( (or res depending on how the id is returned by your API)
  3. finish by response.send(recordGetter.serialize(record))

This is just guess-coding, but the idea is: create via you API, and then get it via Forest API and return it.

1 Like

It’s working !!!
I had to import
const {
} = require(“forest-express-sequelize”);
const recordGetter = new RecordGetter(category);
and add an await before the serialisation
const serialized = await recordGetter.serialize(record);
But it’s working !!

Thank you !

1 Like