Jump to content

Webhook setup for New ticket generate in WHMCS


Go to solution Solved by simranjeet,

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

 
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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());
  }
});

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by pRieStaKos
Link to comment
Share on other sites

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.

Screenshot_20.png

Screenshot_21.png

Link to comment
Share on other sites

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/ "


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated