How can i pass parametar from my end point to controller

System Information
  • Strapi Version: 3.6.8
  • Operating System: Win10
  • Database: mariadb
  • Node Version: v12.18.3
  • NPM Version:
  • Yarn Version:

Hello all,

i have custom router

“method”: “GET”,
“path”: “/MyScript/get”,
“handler”: “MyScript.MyScript”,
“config”: {
“policies”: []

and would like to pass parametars to my script “MyScript” i would like to call “http://localhost:1340/MyScript/get?par0=1313&par1=1231&par2=3134
and be able to get values of par0, par1, par2 in controller. but every time i get is 403 return.
route is allowed in strapi settings.

does anyone know something about or have done anything?

Hi @WardenCommander,

For starters we should try to fix the 403 status code. It means you are not allowed to access the route. You can change that in the permissions for your role.
See the docs on how to do that:

Hello @boaz

thank you for reply,

I checked my route and its active.
My question is how to define route that i can access parameters in query.

If i define route as:

“method”: “GET”,
“path”: “/MyScript/get/:id”,
“handler”: “MyScript.MyScript”,
“config”: {
“policies”: []

then there is no problem.

But i would like my path to be: “path:/MyScript/get” as i would like to pass 1 or 4 parameters into my function and return xml

You can access the :id inside the controller by using ctx.params to get the parameters

const { id } = ctx.params;

this would extract the :id that was requested if you are sending this an array you can desctructure it but I would then send it with more params


Hello @Eventyret

I know how to get id what i need is other parameters, here is a image of interface i need to have, disregard “php” part

You can try using ctx.request.query to get the query params.

Like this:

const { objectid, datefrom, dateto, persons } = ctx.request.query;

thank you, this solve it :slight_smile:

@WardenCommander Awesome!
Feel free to mark my answer as the solution to your question :slight_smile:

1 Like