I am trying to connect Mautic API via PHP useing PHP library.
Tried with basci authntication and Oauth1 but didn;t get successfull. It always throw an error like “Requested URL not found: /mautic/index.php/api/contacts?orderByDir=ASC. ‘message’ => string ‘Requested URL not found: /mautic/index.php/api/contacts?orderByDir=ASC (error is deprecated as of 2.6.0 and will be removed in 3.0. Use the errors array instead.)’ (length=166)
‘code’ => int 404”
This is my code.
Code:
include "../vendor/autoload.php";
require_once '../lib/MauticApi.php';
use MauticAuthApiAuth;
use MauticMauticApi;
$apiUrl = "http://localhost/mautic/index.php";
$settings = array(
'AuthMethod' => 'BasicAuth', // Must be one of 'OAuth' or 'BasicAuth'
'userName' => 'admin', // The username for authentication; Best practise would be to set up a new user for each external site
'password' => 'Admin123!', // Make this a Long passPhrase e.g. (Try.!wE4.And.*@ws4.Guess.!a4911.This.*-+1.Sucker.!)
'apiUrl' => 'http://localhost/mautic/index.php', // NOTE: Required for Unit tests; *must* contain a valid url
);
try {
// Initiate the auth object specifying to use BasicAuth
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings, 'BasicAuth');
if ($auth) {
$api = new MauticApi();
$contactApi = $api->newApi('contacts', $auth, $apiUrl);
// Get Contact list
$results = $contactApi->getList();
var_dump($results);
} else {
echo "Something went wrong!";
}
} catch (Exception $e) {
echo "Mautic not connected!";
}</div>
I am trying to connect Mautic API via PHP useing PHP library.
Tried with basci authntication and Oauth1 but didn;t get successfull. It always throw an error like “Requested URL not found: /mautic/index.php/api/contacts?orderByDir=ASC. ‘message’ => string ‘Requested URL not found: /mautic/index.php/api/contacts?orderByDir=ASC (error is deprecated as of 2.6.0 and will be removed in 3.0. Use the errors array instead.)’ (length=166)
‘code’ => int 404”
This is my code.
[code]include “…/vendor/autoload.php”;
require_once ‘…/lib/MauticApi.php’;
use MauticAuthApiAuth;
use MauticMauticApi;
$apiUrl = "http://localhost/mautic/index.php";
$settings = array(
'AuthMethod' => 'BasicAuth', // Must be one of 'OAuth' or 'BasicAuth'
'userName' => 'admin', // The username for authentication; Best practise would be to set up a new user for each external site
'password' => 'Admin123!', // Make this a Long passPhrase e.g. (Try.!wE4.And.*@ws4.Guess.!a4911.This.*-+1.Sucker.!)
'apiUrl' => 'http://localhost/mautic/index.php', // NOTE: Required for Unit tests; *must* contain a valid url
);
try {
// Initiate the auth object specifying to use BasicAuth
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings, 'BasicAuth');
if ($auth) {
$api = new MauticApi();
$contactApi = $api->newApi('contacts', $auth, $apiUrl);
// Get Contact list
$results = $contactApi->getList();
var_dump($results);
} else {
echo "Something went wrong!";
}
} catch (Exception $e) {
echo "Mautic not connected!";
}[/code]