Jump to content

Hook to send order details to 3rd party SAAS


PatInt

Recommended Posts

Hi there

I use ActiveCampaign (AC) for marketing and PM.

I have a webhook that creates a contact in AC, when a new client account is created. Just First, Last and Email currently. The hook also Tags the contact with [WHMCS], so I know where they came from. I would like to Tag them with the service they order/subscribe to. I looked into Provisioning modules, but some are obfuscated, so I can't get access to the module details, so didn't pursue that any further, but I can't see a hook that would provide this info either.

I'm happy to run an update query via cron, to update contacts in AC, once a day, if that's what is needed. I would happily outsource this as my PHP skills are not at that level.

So my question is - does anyone have any thoughts on the best way that this could be achieved?

Thanks

Link to comment
Share on other sites

The AfterModuleCreate hook could be used too. It returns all relevant data. And there is also AfterModuleTerminate, which can be used to remove the tags from AC when the service is terminated.

For domains, you can use PreDomainRegister / PreDomainTransfer. However, there is no hook that is executed when a domain has expired or transferred out. I guess it would be the best to do it via a cronjob, also because manual status changes are not captured at "AfterModuleTerminate", as the terminate module function is not triggered and  a combination of serveral hooks would be necessary. A cronjob would ensure that the data in AC is always correct. 

Edited by string
Link to comment
Share on other sites

On 31/12/2021 at 5:11 PM, string said:

The AfterModuleCreate hook could be used too. It returns all relevant data. And there is also AfterModuleTerminate, which can be used to remove the tags from AC when the service is terminated.

For domains, you can use PreDomainRegister / PreDomainTransfer. However, there is no hook that is executed when a domain has expired or transferred out. I guess it would be the best to do it via a cronjob, also because manual status changes are not captured at "AfterModuleTerminate", as the terminate module function is not triggered and  a combination of serveral hooks would be necessary. A cronjob would ensure that the data in AC is always correct. 

Thanks for the reply.

I've added the AfterModuleCreate and AfterModuleTerminate hooks, but I'm missing something when extracting the array data.
In the code below, I've shown the details I use to compile the AC $post array. This format works for my WHMCS ClientAdd hook, that captures accounts created without purchases, so I know the code is good there.

What am I missing?

Thanks

add_hook('AfterModuleTerminate', 1, function($vars) {
    $myserviceid = "Service ID: " . $vars['serviceid'];
    $myuserid = "User ID: " . $vars['userid'];
    $mypid = "P ID: " . $vars['pid'];
    $myserverid = "Server ID: " . $vars['serverid'];
    $mydomain = "Domain: " . $vars['domain'];
    $mynodtype = "Mod Type: " . $vars['moduletype'];
    $email = "clientsdetails: " . $vars['clientsdetails'][2];
    $firstname = "clientsdetails: " . $vars['clientsdetails'][0];
    $lastname = "clientsdetails: " . $vars['clientsdetails'][1];


$post = array(
    'email'                    => $email,
    'first_name'               => $firstname,
    'last_name'                => $lastname,
    'tags'                     => $myserviceid,
    // assign to lists:
    'p[2]'                   => 2, // example list ID (REPLACE '123' WITH ACTUAL LIST ID, IE: p[5] = 5)
    'status[2]'              => 1, // 1: active, 2: unsubscribed (REPLACE '123' WITH ACTUAL LIST ID, IE: status[5] = 1)
    // use the folowing only if status=1
    'instantresponders[2]' => 1, // set to 0 to if you don't want to sent instant autoresponders
    'p[1]'                    => 1, // some additional lists?
    'status[1]'            => 1, // some additional lists?
    'instantresponders[1]' => 1, // set to 0 to if you don't want to sent instant autoresponders
);

 

Link to comment
Share on other sites

5 hours ago, PatInt said:

Thanks for the reply.

I've added the AfterModuleCreate and AfterModuleTerminate hooks, but I'm missing something when extracting the array data.
In the code below, I've shown the details I use to compile the AC $post array. This format works for my WHMCS ClientAdd hook, that captures accounts created without purchases, so I know the code is good there.

What am I missing?

Thanks


add_hook('AfterModuleTerminate', 1, function($vars) {
    $myserviceid = "Service ID: " . $vars['serviceid'];
    $myuserid = "User ID: " . $vars['userid'];
    $mypid = "P ID: " . $vars['pid'];
    $myserverid = "Server ID: " . $vars['serverid'];
    $mydomain = "Domain: " . $vars['domain'];
    $mynodtype = "Mod Type: " . $vars['moduletype'];
    $email = "clientsdetails: " . $vars['clientsdetails'][2];
    $firstname = "clientsdetails: " . $vars['clientsdetails'][0];
    $lastname = "clientsdetails: " . $vars['clientsdetails'][1];


$post = array(
    'email'                    => $email,
    'first_name'               => $firstname,
    'last_name'                => $lastname,
    'tags'                     => $myserviceid,
    // assign to lists:
    'p[2]'                   => 2, // example list ID (REPLACE '123' WITH ACTUAL LIST ID, IE: p[5] = 5)
    'status[2]'              => 1, // 1: active, 2: unsubscribed (REPLACE '123' WITH ACTUAL LIST ID, IE: status[5] = 1)
    // use the folowing only if status=1
    'instantresponders[2]' => 1, // set to 0 to if you don't want to sent instant autoresponders
    'p[1]'                    => 1, // some additional lists?
    'status[1]'            => 1, // some additional lists?
    'instantresponders[1]' => 1, // set to 0 to if you don't want to sent instant autoresponders
);

Sorry - that's not correct.

    $email = $vars['clientsdetails'][2];
    $firstname = $vars['clientsdetails'][0];
    $lastname = $vars['clientsdetails'][1];

Is what the vars look like

Link to comment
Share on other sites

  • 1 year later...

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.

×
×
  • 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