Thanks Adam…answers to your obvious questions…
Yes its on a uppercase first letter subdomain … https;//mydomain.com/Mautic/
not in the root…Here is my best code that shows how i addressed saving a contact and retrieving a contact by id number… It appears ok other than the fact that it is not getting in with the API key i generate… as if i put a bad pw in the program i see the exact same result when a good pw is used… Is it possible my security is so good that it is rejecting my user and pw by http… i remember i used to to that long ago to get direct to cpanel via http but security has long since shut that down.
But the way its looking is something and could be security may be keeping me out an required the oath2 service… Have you conquered the oath2 service that would be great if you have any scripts that work with the oath2… Below is my two final that i believe are correct but do not ``allow adding the new lead or retrieving the contact by id either… really does seem like some security holding back… I tried logged into Mautic and logged out and nothing mattered including using a wrong pw for the program and same results with good or bad pw…
Below are two programs one for adding a new contact and one for retrieving a contact by id.
&&&&&&&&&&&&&&&&&&&&& ADDING A NEW CONTACT &&&&&&&&&&&&&&&
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
echo "
1. Adam Testing by Tom.
";
// You need to Authenticate with a BASE64 encoded Username and Password
// Note: The u and p are the exact credentials that I use to access my mautic.
$username = "XXXXXX;
$password = "XXXXXX";
$str = $username . ":" . $password; echo "
str: " . $str . "
";
$apikey = base64_encode($str);
echo "API KEY = $apikey
";
// note: Full path to my mautic.. yes M uppercase (so mautic is in sub dir = /Mautic
// note: the url below minus the /api/ is the exact url i use to enter my mautic.
$endpoint = "https://XXXXXXpremium.com/Mautic/api/";
echo "ENDPOINT = $endpoint
";
$url = $endpoint . "contacts/new"; echo "
URL: " . $url . "
";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
## SET TO POST AND GET BUILD THE DATA ******************************
// I used the exact data owner, firstname etc that you used to make it easier to verify the data when you look at it.
curl_setopt($curl, CURLOPT_POST, 1); // Set as a POST
$data = array(
'owner' => 1,
'firstname' => 'Kelly',
'lastname' => 'Mouse',
'email' => 'kelly@disneyworld.com',
'ipAddress' => $_SERVER['REMOTE_ADDR'],
'overwriteWithBlank' => true
);
echo "
";
print_r($data);
echo "
";
# curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
## ******************************************************************
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $apikey));
curl_setopt($curl,CURLOPT_HEADER,true); // copied from th PHP AbstractAuth.php "function makeRequest".
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Set the result output to be a string.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // copied from th PHP AbstractAuth.php "function makeRequest".
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$data = curl_exec($curl);
echo "DATA = $data
";
if ($data === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occurred during curl exec. Additional info: ' . var_export($info));
}
else
{
$info = curl_getinfo($curl);
var_export($info);
curl_close($curl);
}
echo "
";
print_r($data);
echo "
";
exit;
// &&&&&&&&&&&&&&&&&&& END OF ADDING CONTACT &&&&&&&&&&&&&&&&&&
**Second program commences...\n\n**
// &&&&&&&&&&&&&&&&& BEGIN RETRIEVE A CONTACT BY ID &&&&&&&&&&&&&&&&&&&\n\n
Next is re-trievieng an existing contact by ID.
<?php
// TO GET A CONTACT Do something like this:
/* Authenticate As above example */
$username = "XXXXXXXX";
$password = "XXXXXXXX";
$str = $username . ":" . $password; echo "
str: " . $str . "
";
$apikey = base64_encode($str);
echo "APIKEY = $apikey
";
$endpoint = "https://XXXXXXpremium.com/Mautic/api/";
echo "Sendpoint - $endpoint
";
// The $id is the contact's ID
$id=9;
echo "ID = $id
";
$url = $endpoint . "contacts/" . $id; // echo "URL: " . $url ;
echo "
$url
";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $apikey)); echo "
apikey: " . $apikey . "
";
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Set the result output to be a string.
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$data = curl_exec($curl);
if ($data === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additional info: ' . var_export($info));
}
else
{
curl_close($curl);
}
$decodedContact = json_decode($data);
echo "
decodedContact
";
echo "
";
print_r($decodedContact);
echo "
";
exit;
// &&&&&&&&&&&&&&&&& END OF RETRIEVING A CONTACT BY ID &&&&&&&&&&&&&&