Jump to content

WHMCS webhook to Zapier


Rusky

Recommended Posts

Hi, hope someone can help me with this one...

I'm trying to create a ClientAdd webhook that triggers a Catch Hook in Zapier.

So far I've...

1. Created a file called ClientAdd.php in includes/hooks (see code below)

2. Setup the Catch Hook in Zapier. 

I'm not a developer, so not sure if my code below is correct. I feel something might be missing to make this work properly or the webhook isn't triggering in WHMCS. Anyone able to assist?

<?php
/**
 * Register hook function call.
 *
 * @param string $hookPoint The hook point to call
 * @param integer $priority The priority for the given hook function
 * @param string|function Function name to call or anonymous function.
 *
 * @return Depends on hook function point.
 */
add_hook('ClientAdd', 1, function ($vars)
{
    $userid = $vars['userid'];
    $firstname = $vars['firstname'];
    $lastname = $vars['lastname'];
    $companyname = $vars['companyname'];
    $email = $vars['email'];
    $address1 = $vars['address1'];
    $address2 = $vars['address2'];
    $city = $vars['city'];
    $state = $vars['state'];
    $postcode = $vars['postcode'];
    $country = $vars['country'];
    $phonenumber = $vars['phonenumber'];
    $tax_id = $vars['tax_id'];
    $emailoptout = $vars['emailoptout'];
    $notes = $vars['notes'];

    // Run code here...
    
    https://hooks.zapier.com/hooks/catch/XXXXXXX/XXXXX/silent/    (URL changed for security)
});

 I'm also unable to see anywhere in the logs where I can confirm that the WHMCS webhook has run after the ClientAdd event is triggered? As far as I can tell nothing is being triggered on the Zapier end by my code above.

Cheers
John

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

Hey guys, so in case somebody else is looking for this.. (I am quite amazed that this is not a built in feature in WHMCS yet.. but oh well):

Rusky you can't just paste the webhook URL and expect it to receive parameters, it's PHP code and you need to utilizie it.

Here is an example of a hook file, that will send the first & last name of new customers, to your zapier hook:

add_hook('ClientAdd', 1, function ($vars)
{
    $userid = $vars['userid'];
    $firstname = $vars['firstname'];
    $lastname = $vars['lastname'];

    // Posting of the info -> Zapier Webhook
    echo file_get_contents('https://hooks.zapier.com/hooks/catch/WEBHOOK/', false, stream_context_create([
    'http' => [
        'method' => 'POST',
        'header'  => "Content-type: application/x-www-form-urlencoded",
        'content' => http_build_query([
            'firstname' => $firstname, 'lastname' => $lastname
        ])
    ]
]));
});

 

So you can adjust it to send whatever parameters you'd like bout your new order. Here you can find the full reference of available parameters. 

 

Ilya

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