Add PHP API
-
-
NodeBB output:
2/3 19:20 [32175] - warn: Route requested but not found: /api/v1/topics 2/3 19:20 [32175] - error: /api/v1/topics Error: invalid csrf token at verifytoken (/home/me/www/forums/nodebb/node_modules/csurf/index.js:237:11) at Object.csrf [as applyCSRF] (/home/me/www/forums/nodebb/node_modules/csurf/index.js:100:7) at Object.middleware.buildHeader (/home/me/www/forums/nodebb/src/middleware/middleware.js:191:13) at /home/me/www/forums/nodebb/src/routes/index.js:200:15 at Layer.handle [as handle_request] (/home/me/www/forums/nodebb/node_modules/express/lib/router/layer.js:82:5) at trim_prefix (/home/me/www/forums/nodebb/node_modules/express/lib/router/index.js:302:13) at /home/me/www/forums/nodebb/node_modules/express/lib/router/index.js:270:7 at Function.proto.process_params (/home/me/www/forums/nodebb/node_modules/express/lib/router/index.js:321:12) at next (/home/me/www/forums/nodebb/node_modules/express/lib/router/index.js:261:10) at /home/me/www/forums/nodebb/src/routes/index.js:158:11
-
I got it...
-
I use not standart url - localhost:4567/forum
Url API replace to: localhost:4567/forum/api/v1/... -
curl -H "Authorization: Bearer fe9de6fb6-1234-44b7-8bbc-b5073fd1edef" --data "title=Тестовыйпост&content==роверкасодержимогопоста&cid=" http://localhost:4567/forum/api/v1/topics
Out:
{ "code": "not-authorised", "message": "You are not authorised to make this call", "params": {}
What is it?
-
@sergej-saveljev It looks like you're not passing in a
cid
...That error message seems like the token does not exist, or is not related to a proper uid...
-
-
Yes, everything is OK! Thanks!
-
<?php class nodebb { function category_add ($params='name=Default category name', $token='e9de6fb6-1234-5678-8bbc-b5073fd1edef'){ shell_exec('/usr/bin/curl -H "Authorization: Bearer '.$token.'" --data "'.$params.'" http://localhost:4567/forum/api/v1/categories'); } } $nodebb = new nodebb; $nodebb->category_add(); return false;
Now it's much easier
Copyright © 2024 NodeBB | Contributors