PHP & JSON: Wordpress Mautic Integration Problems with Webhook Handler Script

Hi,`

I’m trying to integrate Wordpress and Mautic, and documentation on scripting is deficient on the internet. I have a script that translates webhooks sent by Memberpress. Most registrations are free ones, and users fill out username, email, password, and password again. I do not know how to add more than one tag to tag a user in Mautic. That’s one issue, and it’s the minor issue. Number 2 issue is in a new paragraph, and it’s about adding users to segments and campaigns via the handler script. Excerpts from my script are below if I can add them here.

Number 2: How do I add a user to either a Mautic form or a Mautic segment via a webhook. I tried adding a filter to a segment based on a tag. The choices were “including”, “excluding”, “empty”, and “not empty”. I added two filters: “not empty” and "including (the tag added by the script). It seemed to assign users to segments randomly. I can’t make sense of it.

I want to be able to add users to segments. I have a double optin system with a pending segment and a confirmed segment. I can either add new people to both and remove them from pending when they confirm email via a link in an email or add them to a form somehow. That way, I can add a drip campaign to the confirmed segment so that they they don’t stop receiving the drip campaign after confirming email.

Some sample code from the script:

// decode the incoming data
$data = json_decode($HTTP_RAW_POST_DATA,true);

// grab woocommerce values
$email = $data['email'];
$firstname = $data['first_name'];
$username = $data['username'];
$tag = 'Pend Rabbit Hole Tag';

(Mautic login stuff) and then...

$curl = curl_init();
// Set some options - we are passing in a user agent too here
  curl_setopt_array($curl, array(
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_URL => "https://".$loginname.":".$password."@".$siteurl."/api/contacts/new",
  CURLOPT_USERAGENT => 'Mautic Connector',
  CURLOPT_POST => 1,
// posting the payload
// make sure the last line doesnt have a comma
  CURLOPT_POSTFIELDS => array(
    'firstname' => $firstname,
    'email' => $email,
    'tags' => $tag
  )
));
$resp = curl_exec($curl);
curl_close($curl);

(error log settings and such)

Thanks.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.