DennisHermannsen Posted August 27 Share Posted August 27 If you're having trouble, simplify your code: <?php add_hook('TicketOpenAdmin', 1, function($vars) { logActivity('New ticket opened!'); }); I've just tested using the above script and a new entry was added to the Activity Log. If it doesn't work, you have an issue with the hook not being registered in WHMCS. If it does work, the issue is you code inside of the hook. Also, there's no errors on the screenshot you provided of the hook debug lines. 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 27 Author Share Posted August 27 I have do same thing and I am only received this in activity log-> Hooks Debug: No Hook Functions Defined for AdminLogin Hooks Debug: Called Hook Point AdminLogin Hooks Debug: Hook Defined for Point: AfterRegistrarRenewalFailed - Priority: 1 - Function Name: (anonymous function) 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 27 Share Posted August 27 Disable the Hook Debug Log. It'll just tell you if a hook is executed, but it's difficult to find the specific line as multiple hooks are executed every second of you browsing the admin interface. 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 27 Author Share Posted August 27 18 minutes ago, DennisHermannsen said: Disable the Hook Debug Log. It'll just tell you if a hook is executed, but it's difficult to find the specific line as multiple hooks are executed every second of you browsing the admin interface. Okay, I've disabled the hook log, but how can I retrieve the data of the most recently created ticket and send it to my webhook URL? Let me explain you what exactly i am trying to do from my end: First, I created a file named open_ticket.php in the includes/hooks/ directory. I wrote the code in this file, which I previously shared with you in the chat above. After that, I created a ticket in the WHMCS system. However, when I checked the webhook file at the URL I set to receive the data, I unfortunately didn’t receive anything. I have use both event TicketOpenAdmin and TicketOpen but still same result. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 27 Share Posted August 27 Create a simple hook that does I nothing else than print something to the activity log. If that works, you have an issue with the webhook or the data that's being sent. 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 27 Author Share Posted August 27 10 minutes ago, DennisHermannsen said: Create a simple hook that does I nothing else than print something to the activity log. If that works, you have an issue with the webhook or the data that's being sent. Ok this is my code in my hook file-> <?php if (!defined("WHMCS")) { die("This file cannot be accessed directly"); } function log_ticket_creation($vars) { logActivity("A ticket was created with ID: " . $vars['ticketid']); } add_hook('TicketAdd', 1, 'log_ticket_creation'); and after creating a ticket nothing display in activity log 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 27 Author Share Posted August 27 Could we schedule a Zoom call? I'd like to show you the exact issue I'm facing on my end. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 27 Share Posted August 27 You're changing the hook point in almost every reply. Stick to one and try to troubleshoot that one. There's no "TicketAdd" hook point. That's why it won't work. Try with this very simple hook - and make no changes to it: <?php add_hook('TicketOpenAdmin', 1, function($vars) { logActivity('New ticket opened!'); }); Create the ticket from your admin area and check the activity log. If it prints "New ticket opened!", it works perfectly fine. Next, try this variant of your original hook: <?php add_hook('TicketOpen', 1, function ($vars) { try { logActivity('Setting data...'); $data = [ "ticketid" => $vars["ticketid"], "ticketmask" => $vars["ticketmask"], "userid" => $vars["userid"], "deptid" => $vars["deptid"], "deptname" => $vars["deptname"], "subject" => $vars["subject"], "message" => $vars["message"], "priority" => $vars["priority"] ]; logActivity(print_r($data)); } catch (Exception $e) { // If error, write to Activity log logActivity('[TicketOpen] Error: ' . $e->getMessage()); } }); 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 28 Author Share Posted August 28 11 hours ago, DennisHermannsen said: You're changing the hook point in almost every reply. Stick to one and try to troubleshoot that one. There's no "TicketAdd" hook point. That's why it won't work. Try with this very simple hook - and make no changes to it: <?php add_hook('TicketOpenAdmin', 1, function($vars) { logActivity('New ticket opened!'); }); Create the ticket from your admin area and check the activity log. If it prints "New ticket opened!", it works perfectly fine. Next, try this variant of your original hook: <?php add_hook('TicketOpen', 1, function ($vars) { try { logActivity('Setting data...'); $data = [ "ticketid" => $vars["ticketid"], "ticketmask" => $vars["ticketmask"], "userid" => $vars["userid"], "deptid" => $vars["deptid"], "deptname" => $vars["deptname"], "subject" => $vars["subject"], "message" => $vars["message"], "priority" => $vars["priority"] ]; logActivity(print_r($data)); } catch (Exception $e) { // If error, write to Activity log logActivity('[TicketOpen] Error: ' . $e->getMessage()); } }); Ok let me check i will update you if its work. 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 28 Author Share Posted August 28 I've created a ticket from the admin area, but I'm getting the same result. I've followed your instructions as mentioned above, but the issue persists. 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 29 Author Share Posted August 29 Any update? 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted August 29 Share Posted August 29 (edited) Disable the Hooks Debug, run again and for TickerOpenAdmin, try to find an entry with "'New ticket opened!'" for TicketOpen, try to find an entry with "[TicketOpen] Error" or "Setting data..." and below another entry with your data in it. If you are not getting any entry in Activity Log, then you should check your server log, as the php script is not properly running and should return the cause in server log. Edited August 29 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 29 Author Share Posted August 29 I haven’t received any errors in the error log file, nor did I receive a notification when I created a ticket in the WHMCS system. The logs only show ticket deletions and email send events. I’m unsure what the issue might be, as I’ve tried multiple approaches without success. I’m also uncertain if there’s any additional setting in WHMCS that I need to enable or adjust. Despite following the suggestions provided, I’m still encountering problems with the hook. I’m not sure what I might be doing wrong. I have created my file in the directory specified in the WHMCS hook documentation. In this directory, there is already a file named example.php which includes instructions on creating a hook for a specific event. I have followed the same steps, but I am still getting the same result. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 29 Share Posted August 29 Are you 100% sure that cache is not enabled on the server? 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 30 Author Share Posted August 30 13 hours ago, DennisHermannsen said: Are you 100% sure that cache is not enabled on the server? Yes I am 100% sure. 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted August 30 Author Share Posted August 30 I turned off all caches 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 2 Share Posted September 2 If you at the top of the hook (right under your php tag) echoes something, can you see it if you access the file from your browser? 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted September 3 Author Share Posted September 3 14 hours ago, DennisHermannsen said: If you at the top of the hook (right under your php tag) echoes something, can you see it if you access the file from your browser? yes 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted September 3 Author Share Posted September 3 Do you have any idea how to resolve this issue? Do I need to make any adjustments in the WHMCS system settings? 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted September 3 Author Share Posted September 3 Quick update: I've found a solution for retrieving recently created ticket data. As you're aware, the hook hasn't been working, and I've tried various approaches to get it functioning, but it still doesn't trigger when a new ticket is created in WHMCS. Given this, I realized that whenever a new ticket is created, the information is stored in the WHMCS database. I checked the relevant table where this data is stored, and now I have the option to retrieve the most recent ticket information directly from the database. I also checked this link, which gave me the idea of how to retrieve information about recently created tickets:->"https://whmcs.community/topic/263697-display-users-tickets-using-a-hook/ " 0 Quote Link to comment Share on other sites More sharing options...
simranjeet Posted September 3 Author Share Posted September 3 Could you please help me with this? If I take a similar approach to setting up the hook to retrieve the most recently created data from the database, would that work for me? 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.