Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions
You are not logged in.
Pages: 1
Hi,
I am trying to add a custom endpoint in the API. So far, I
1) Added the path in swagger.json like this:
"/restapi/myendpoint/{user_id}": {
"get": {
"tags": [
"user"
],
"summary": "",
"description": "",
"produces": [
"application/json"
],
"parameters": [
{
"name": "user_id",
"in": "path",
"description": "User ID",
"required": true,
"type": "string",
"format": "int32"
}
],
"responses": {
"200": {
"description": "",
"schema": {
}
},
"400": {
"description": "Error",
"schema": {
}
}
},
"security": [
{
"login": []
}
]
}
}
2) created a file named myendpoint.php under modules/lhrestapi :
[== PHP ==]
<?php
try {
erLhcoreClassRestAPIHandler::validateRequest();
$user = erLhcoreClassModelUser::fetch((int) $Params['user_parameters']['user_id']);
if ($user instanceof erLhcoreClassModelUser) {
$db = ezcDbInstance::get();
echo json_encode(array('error' => false, 'result' => array('msg' => 'Status changed', 'online' => $user->hide_online == 0)));
} else {
throw new Exception('User could not be found!');
}
} catch (Exception $e) {
echo erLhcoreClassRestAPIHandler::outputResponse(array(
'error' => true,
'result' => $e->getMessage()
));
}
exit();
and
3) added this inside lhrestapi\module.php :
$ViewList['myendpoint'] = array(
'params' => array('user_id')
);
When I try this endpoint, I am getting code 302 (a redirect to /index.php/) as if the route doesn't exist.
Any help will be appreciated. Thanks.
Last edited by kdim (2018-08-15 19:38:01)
Offline
Hi kdim,
welcome on the live helper chat forum.
I am really sorry but my basic help do not cover your request.
You can find some info about commercial support and Github issue here:
https://forum.livehelperchat.com/viewtopic.php?id=2255
PeopleInside - Live helper chat - free limited forum support!
For commercial support or GitHub [see FAQ here]
If you want to support this open source project, just donate [see support page]
Something wrong with the forum? [contact a superhero]
Offline
Hi,
1. You have to clear cache after you have do your changes. Or just develop with disable cache
Offline
Pages: 1