Hi there,
I’m stuck and would really appreciate some help.
I’ve installed 2 copies of Mautic on a linode VPS, each on its own domain.
The installations work fine and so far its an awesome product, my only issue is i can’t for the live of me figure out how to implement the API.
I’ve downloaded the zip file at (https://github.com/mautic/api-library), first off, the documentation is a little unclear on where i need to put it.
Does it go onto my Mautic server, in each of the domains or can i use it on my 3rd domain where i’m capturing my leads so that i can API these leads to my mautic instances?
I’ve tried both and so far nothing seems to work.
in someplaces i saw that the URL to include the class files looked like this:
require_once DIR . ‘/lib/Mautic/MauticApi.php’;
however when downloading the api library its should actually just be require_once DIR . ‘/lib/MauticApi.php’; // not sure if i’m missing something.
I have tried all the examples i could find but nothing seems to work for me.
Currently i have the ‘lib’ extraced on my 3rd domain (one without a Mautic installation), and made a script that must just authenticates. (I used this code - https://developer.mautic.org/#oauth-2)
the only difference to the example code is i added the following line to the top of my script.
require_once DIR . ‘/lib/MauticApi.php’;
however the script seems to die on the following code:
$initAuth = new ApiAuth();
My mautic installation uses index.php at the end of my domain so i have tried my baseUrl value as both with and without it.
my ‘callback’ value is the URL to my script.
here is my code:
<?php
require_once DIR . ‘/lib/MauticApi.php’;
echo “<br>------------ 1 --------------<br>”;
use Mautic\Auth\ApiAuth;
echo “<br>----------- 2 ---------------<br>”;
// $initAuth->newAuth() will accept an array of OAuth settings
$settings = array(
‘baseUrl’ => ‘https://One_of_my_mautic_domains/index.php’,
‘version’ => ‘OAuth2’,
‘clientKey’ => ‘Key_found_in_mautic’,
‘clientSecret’ => ‘SecretKey_found_in_mautic’,
‘callback’ => ‘https://My_3rd_domain/mautic_api/auth.php’
);
echo “<br>----------- 3 ---------------<br>”; // this is the last echo that gets displayed
// Initiate the auth object
$initAuth = new ApiAuth();
echo “<br>----------- 4 ---------------<br>”;
$auth = $initAuth->newAuth($settings);
echo “<br>----------- 5 ---------------<br>”;
// Initiate process for obtaining an access token; this will redirect the user to the authorize endpoint and/or set the tokens when the user is redirected back after granting authorization
var_dump($auth);
echo “<br>----------- 6 ---------------<br>”;
if ($auth->validateAccessToken()) {
if ($auth->accessTokenUpdated()) {
$accessTokenData = $auth->getAccessTokenData();
//store access token data however you want
}
}
Any help would be appreciated.