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?
boaz
September 24, 2021, 2:11pm
2
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
WardenCommander:
hank 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
so
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
2 Likes
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
boaz
September 24, 2021, 3:47pm
6
@WardenCommander
You can try using ctx.request.query
to get the query params.
Like this:
const { objectid, datefrom, dateto, persons } = ctx.request.query;
3 Likes
boaz
September 26, 2021, 2:11pm
8
@WardenCommander Awesome!
Feel free to mark my answer as the solution to your question
1 Like