Is anyone willing to share a template to allow me to communicate with the Mautic APi for $100?

Oh by the way can you tell me what this little item does for me… Thanks…
‘overwriteWithBlank’ => true

curl_setopt($curl, CURLOPT_POST, 1); // Set as a POST

$data = array(
    'owner' => 1,
    'firstname' => 'Minnie',
    'lastname'  => 'Mouse',
    'email'     => 'minnie@disneyworld.com',
    'ipAddress' => $_SERVER['REMOTE_ADDR'],
    'registration_tracking_url' => 'https://www.idxseopremium.com/idxseo/6682-IRON-SQUARE-Street-Las-Vegas-Nevada-89148-mls-2041178/',
    'title' => '6682 IRON SQUARE Street, Las Vegas, Nevada 89148 MLS# 2041178',    
    'overwriteWithBlank' => true


You got me wrong here…
I got the API to work. And it works quite nice.
Fair enough, I’ll share my code. with examples…
But it is late here and the weekend, give me a day or two.

I wasn’t suggesting it did not work for you… it works fine for many but those of us who are a little slower on this tech stuff… is a lot harder than for the more technical folks like yourself…
Below is an example of just one of the items i would love to have … the ability to put an OATH2 header on this and run the below simple program… but its beyond me…I am having trouble getting a Basic header to run code… But please if you have this code already and willing to share… and/or work with me to get it working on my hard drive… that crispy hundred dollar bill in this post awaits you… once i have and understand the OATH2 header set up and function it should be simple to add as many code snippits as i like to the header and run them without problems…

With the below few lines of code all i need to do is grab the segment ID and the contact id and drop them in the box and bingo i have placed the contact into the segment… So easy peasy if i ever get past building the header to run all this… Thanks in advance.

<?php
//...
$response = $segmentApi->addContact($segmentId, $contactId);
if (!isset($response['success'])) {
    // handle error
}

overwriteWithBlank: If true, then empty values are set to fields. Otherwise empty values are skipped

Thank you…

@tommytx123 I feel your pain.

I am way out of my depth trying to create a webhook that will inject a new contact into Mautic using basic auth. I have used the code @joeyk uses in his webhook tutorial but I get 401 error - access denied. Of course API and Basic auth enabled.

It works for Joey in his tut but not for me. Now I am drowning in a sea of headers, authorisations, and base 64. Not being a coder I am a blind monkey cutting and pasting hoping for the best.

Have you had luck? Can you offer any guidance? I feel like the issue lies with

CURLOPT_URL => "https://".$loginname.":".$password."@".$siteurl."/api/contacts/new",

Maybe it needs to be encoded somehow?

Below is Joey’s code for adding a contact with basic auth.

// This is the Mautic API part


// Set your login and site URL
$loginname = 'XXXXXXX';
$password = 'XXXXXXXX';
$siteurl = 'mautic.XXXXX.XX';
$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
  CURLOPT_POSTFIELDS => array(
    'firstname' => $user_custom_data_name,
    'surname' => $user_custom_data_surname,
    'email' => $user_email,
//	'3rd_party_software' => $3rd_party_software,
    'tags' => $tag
  )
));
curl_exec($curl);

Hey join the club… along with thousands of others whining about the same thing… As I search history and starting to search by “Confused trying to get basic to work” and amazed by how many it just don’t work for… Between Joeyk, adiux, adam.clark and dozens of others that I found in many searches… I put together a basic that sorta worked… but would not do what i needed is the little piece of code that sets up a lead to connect with a segment so it will start an automatic campaign…so all i can say is study all the code on this page and there is much and keep experimenting till you get something that works…
The one closet that i got to work took joeyks initial code and then adam added in the 64 bit to encode the stuff and that did the best but not what i need yet…
It can’t be this hard… I guess those who have fully functional copies (if they are any) are not willing to share them… I know what you mean when you say all these bits and pieces are very difficult for a non programmer… we need working models… not bits and pieces… but these are volunteer folks and they have no obligation to help at all so I am very thankful for those who at least try to help us…
I Know they say teach us to fish … but when you are a non programmer… fishing won’t help here only php coding will… LOL.
I will certainly let you know if i come up with a fully function basic that can drive this stuff… that i can understand…
Quentin is a super programmer and has been helping me but seems my php is just to week to catch on to what he is trying to do and he does not have the ability to set it up fully on his end… but I will not give up till i get it to work… one day…

I wrote some PHP code that puts leads in a segment. But it doesn’t use the API, it writes directly in the Mysql database. I know this probably isn’t the neatest way, but it works, and it didn’t take me much more than an hour.

We are glad that there are volunteers here who are trying to help. But I have the impression that there are no people on this forum who really have knowledge of the inner workings of Mautic.

Those people who do have that knowledge are probably busy with more important things. And of course everything has its price. But despite that, it’s a shame.

Well i don’t mind the dirty way… as i am pretty avid in php and mysql… so if I had any idea what data to place in the db that allow it to tie the segment to the lead so that the segment will fire of a campaign the at the next firing of the campaign that the segment called out…
Right now I am working with taking the data from another Modal form that pops up and transfer that data to the basic mautic form which has the ability to use one of its Actions to tell the form when it arrives with the lead to put that lead into a segment that will of course be picked up when the campaign cron fires again… maybe 5 min and run the lead thru that campaign. That seems to be working but getting all the data to transform to the Mautic register form is a little tricky for me…
Would love to see what you have to see if it can be adapted to work for me…Thanks in advance if you do post what you have… I am sure it would help others…
Oh why am I transferring from a Modal register existing form to the Mautic form…
Mainly since i can’t figure out how to get the API to send my lead data and the segment thru the API as it should go… The modal form the developer put on my site does all that but he has hidden the modal actual code from me… and I can see it all with Chrome tool box but for the world of me i have not been able to find the actual modal register form using many ways of search…I suspect its coming from off site… but not sure…
I copied this code from above… its exactly what i need but cannot get it to work with basic or OAth2… that would be fantastic…

<?php
//...
$response = $segmentApi->addContact($segmentId, $contactId);
if (!isset($response['success'])) {
    // handle error
}

This really simple tad of code ties the contact to the segment and i cannot figure out how to add it to basic or 0ATH2… due to my limited php…
That is the tiny bit of code that Mautic uses supposedly with the basic or oath2…
So its simple for me to get the contact to go thru Mautic API but not the segment crap…

I guess the problem with this is also that it is quite complex. The problem can be on various levels:

  • Client
  • Firewall
  • Server (CORS)
  • Browser (CORS)
  • PHP
  • Mautic
  • etc.

A good first step is to figure out if it works without PHP. You can use a tool like Postman or just use CURL on the command line. Here is an example of how I create a contact:

curl --request POST 'https://localhost/api/contacts/new' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YWR*******pYw==' \
--data-raw '{
    "firstname": "test",
    "lastname": "test",
}'

Maybe add the -v option to get more details: curl -v --request ...

Hope this helps.

Adrian

I have been able to get the basic auth to work and I can now inject the results of a thrive lead from into mautic along with a tag. @adiux 's code snippet is pretty much waht i used in the head to get the authorisation.

The tag is hard coded in the php so that’s not ideal as I would never a different php connector script for each lead form in order to have different tags. But it’s a start. Maybe I can use a hidden field in the thrive form to dynamically create a tag. Will keep playing.

I can use the tag to put someone into a segment and start a campaign that way.

My next issue is to link the previous anonymous contact browsing history with the now known contact. That is a work in progress and success not looking likely.

The other issue is mautic will not attribute future browsing activity to the known contact but still link to the anonymous IP contact. To solve this I fire off a double opt in email with a link. Once the link is clicked mautic will then attribute future activity the known contact.

I like the idea of passing the thrive lead form data to a hidden mautic form on a thank you page. If I can get the form to auto submit on page load then a webhook won’t be needed and I would still have the benefit of the beautiful thrive forms and their in built reporting and AB testing. This may also solve the attribution of historical data. It’s more work though as you would have to create a mautic form which makes this a very non-elegant solution.

Once I have a working solution I will share.

1 Like

Managed to get

“I like the idea of passing the thrive lead form data to a hidden mautic form on a thank you page. If I can get the form to auto submit on page load then a webhook won’t be needed and I would still have the benefit of the beautiful thrive forms and their in built reporting and AB testing. This may also solve the attribution of historical data. It’s more work though as you would have to create a mautic form which makes this a very non-elegant solution.”

To work.

Thanks for the assist…
But what is this ```
Basic YWR*******pYw==’ probably user and pw but how connected…like user some 64 base crap and password… Thanks

And is that all just dump into a php file or is there more above this.
Like this
<?php curl --request POST 'https://localhost/api/contacts/new' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic YWR*******pYw==' \ --data-raw '{ "firstname": "test", "lastname": "test", }' ?>
<?php

curl --request POST 'https://localhost/api/contacts/new' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YWR*******pYw==' \
--data-raw '{
    "firstname": "test",
    "lastname": "test",
}'
?>

Here is what worked for me to inject a new contact via basic auth.

$loginname = 'XXXXXXX';
$password = 'XXXXXXXX';
$encoded_authorization = base64_encode($loginname.":".$password);
$siteurl = 'mautic.xxxxxxx.xx';
$curl = curl_init();

That defines all the variables we need.

 //Set some options - we are passing in a user agent too here
  curl_setopt_array($curl, array(
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_URL => "https://".$siteurl."/api/contacts/new",
  CURLOPT_USERAGENT => 'Mautic Connector',
  CURLOPT_POST => 1,
  CURLOPT_HTTPHEADER => array( 'Authorization: Basic '.$encoded_authorization),

The very last line above users the login and password to generate a base 64 token which I think speaks directly to your question @tommytx123 ?

As a first test I would simply use the command on the terminal.

  1. Genereate a token: e.g. Basic Authentication Header Generator
  2. Replace YWR*******pYw== with your token
  3. Open a terminal and copy paste the command

You should get a JSON response with the successfully created contact.

If that works you know that your server, mautic and your token is ok. Take the next step: Add it to the php code as @robm suggested.

1 Like

Here is my working solution to link Thrive Themes with Mautic. I think this method would work well for most 3rd party form builders, provided they can pass the form variables via URL. I am not using the API connection but it’s an alternative that enables the use of all Mautics actions.

1 Like