# Create custom route

**URL:** https://community.forestadmin.com/t/create-custom-route/2010
**Category:** Help me!
**Created:** [March 4, 2021, 9:34am UTC](https://community.forestadmin.com/t/create-custom-route/2010 "2021-03-04T09:34:30Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Ilias\_El-mhamdi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ilias_el-mhamdi/32/1314_2.png) [@Ilias\_El-mhamdi](https://community.forestadmin.com/u/Ilias_El-mhamdi)
#### Post date: [March 4, 2021, 9:34am UTC](https://community.forestadmin.com/t/create-custom-route/2010/1 "2021-03-04T09:34:30Z")

</div>

Hello,

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,  
Best,  
Ilias

---

<div class="post-metadata">

### Author: ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)
#### Post date: [March 4, 2021, 9:53am UTC](https://community.forestadmin.com/t/create-custom-route/2010/2 "2021-03-04T09:53:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Ilias\_El-mhamdi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ilias_el-mhamdi/32/1314_2.png) [@Ilias\_El-mhamdi](https://community.forestadmin.com/u/Ilias_El-mhamdi)
#### Post date: [March 4, 2021, 10:01am UTC](https://community.forestadmin.com/t/create-custom-route/2010/3 "2021-03-04T10:01:06Z")

</div>

Hi

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

routes/category.js

```javascript

// Create a Category
router.post(
  "/category",
  permissionMiddlewareCreator.create(),
  async (request, response, next) => {
    // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#create-a-record
    console.log("create category");
    const categoryData = request.body.data;
    let departementId;
    try {
      departementId = categoryData.relationships.department.data.id;
    } 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);
      console.log(res);
    } 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;
    next();
  }
);

```

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

Ilias

---

<div class="post-metadata">

### Author: ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)
#### Post date: [March 4, 2021, 1:15pm UTC](https://community.forestadmin.com/t/create-custom-route/2010/4 "2021-03-04T13:15:52Z")

</div>

@Ilias_El-mhamdi,

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

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

```

If you compare you code with our [documentation](https://docs.forestadmin.com/documentation/reference-guide/routes/default-routes#create-a-record). 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.

---

<div class="post-metadata">

### Author: ![Ilias\_El-mhamdi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ilias_el-mhamdi/32/1314_2.png) [@Ilias\_El-mhamdi](https://community.forestadmin.com/u/Ilias_El-mhamdi)
#### Post date: [March 4, 2021, 2:11pm UTC](https://community.forestadmin.com/t/create-custom-route/2010/5 "2021-03-04T14:11:46Z")

</div>

Hello,  
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.

 ![can't be found](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/b/b9716c2523c97bdf61f076c6b5ed45275901b2fb.png)  
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,  
Best,  
Ilias

---

<div class="post-metadata">

### Author: ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)
#### Post date: [March 4, 2021, 2:17pm UTC](https://community.forestadmin.com/t/create-custom-route/2010/6 "2021-03-04T14:17:56Z")

</div>

This might add some processing delay, but you can try using the `RecordGetter`. See this: [Smart field reference link](https://community.forestadmin.com/t/smart-field-reference-link/2011)

The process can be similar to:

1. call `await network.createCategory(categoryTocreate);`
2. call `const record = await recordGetter.get(res.id)` (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.

---

<div class="post-metadata">

### Author: ![Ilias\_El-mhamdi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/ilias_el-mhamdi/32/1314_2.png) [@Ilias\_El-mhamdi](https://community.forestadmin.com/u/Ilias_El-mhamdi)
#### Post date: [March 4, 2021, 2:38pm UTC](https://community.forestadmin.com/t/create-custom-route/2010/7 "2021-03-04T14:38:38Z")

</div>

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

Thank you !

---

<div class="post-metadata">

### Author: ![mostafa\_hatem](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mostafa_hatem/32/2347_2.png) [@mostafa\_hatem](https://community.forestadmin.com/u/mostafa_hatem)
#### Post date: [August 4, 2021, 5:02pm UTC](https://community.forestadmin.com/t/create-custom-route/2010/8 "2021-08-04T17:02:35Z")

</div>

I have the same problem but when i do  
const recordGetter = new RecordGetter(category);  
this gives an error:  
Unexpected error: Cannot read property ‘timezone’ of undefined  
how can i fix this?

---

<div class="post-metadata">

### Author: ![anon94532230](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@anon94532230](https://community.forestadmin.com/u/anon94532230)
#### Post date: [August 5, 2021, 1:40pm UTC](https://community.forestadmin.com/t/create-custom-route/2010/9 "2021-08-05T13:40:41Z")

</div>

Hi @mostafa_hatem !  
Are you on v8 ? If you are, we revamped the scopes in this version and it brings some breaking changes, you can take a look at [the documentation](https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-sql-mongodb/upgrade-to-v8#scopes) to see what you need to do.
