Create new Contact from another server

Your software
My Mautic version is: 3.3.2
My PHP version is: 7.3.28

Your problem
My problem is: I want to create a new contact from a PHP-file on another server than Mautic is installed on. I tried (but I’m open to any solution):

but I can’t get them to work. I don’t have too much idea about this stuff. For example the problem is probably that I don’t know how to use the “include DIR . '/vendor/autoload.php’;” in my PHP-file, as Mautic is on another server as said.

Could somebody please help me how to create a new contact from another server via PHP?

Yes, it is more simple then you think.

This is your data:

$email = 'captain_enterprise-d@starfleet.com';
$firstname = 'Jean-Luc';
$lastname = 'Pickard';
$tag = 'purchased';

This is our curl call:

$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' => $firstname,
    'lastname' => $lastname,
    'email' => $email,
    'tags' => $tag
  )
));
curl_exec($curl);

In case you’d like to dig deeper, I have a detailed description:

2 Likes

Fantastic, thank you soo much! It worked perfectly!

Btw, 2 notes you might want to add on your website to this article (as I had trouble figuring these out):

  • "Enable HTTP basic auth?" must be turned on in Mautic
  • It doesn’t work if the password has special characters like a “.” or a “@” (I had both of these in my pass).

Again, thank you very much for your help!

Good points! Thank you!