Postman is an API testing tool. It is a true delight to use.
https://www.postman.com/
Snipplet to create a contact with simple identification:
Start your code with defining the variables:
<?php
$loginname = 'apiuser';
// Loginname of your API user
$password = 'yourpasswordhere';
// This is the password of the API user
$siteurl = yoursiteurl.tld;
// example: mymautic.com
Add the payload:
$email = 'captain_enterprise-d@starfleet.com';
$firstname = 'Jean-Luc';
$lastname = 'Picard';
$tag = 'purchased';
And execute the API 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 by Joey',
CURLOPT_POST => 1,
// posting the payload
CURLOPT_POSTFIELDS => array(
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $email,
'tags' => $tag
)
));
curl_exec($curl);
That’s it.
If you go with Postman, here are a bunch of API scripts as a Postman collection: