Mautic Community Forums

Error 403 at creating a lead with api

Hello Guys,



i’m actually integrating the mautic API into a website.

After some hours i got it so far that i get a access_token and can get a list of all leads.

But when i try to get a lead by id or try to create a lead i get the following back in my array:

Code:
Array ( [error] => Array ( [code] => 403 [message] => You do not have access to the requested area/action. ) )

Down below is my actual code:
Code:
use MauticAuthApiAuth; use MauticMauticApi; $rootdir = $_SERVER['DOCUMENT_ROOT']; include $rootdir . '/lib/AutoLoader.php';

$settings = array(
‘baseUrl’ => ‘http://mautic.sXXXXXXXXXets.de’,
‘version’ => ‘OAuth2’,
‘clientKey’ => ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’,
‘clientSecret’ => ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’,
‘callback’ => ‘http://XX.XXXXXt.de/mautic/mXXXXXuth.html
);

$auth = ApiAuth::initiate($settings);

if ($auth->validateAccessToken()) {
$apiUrl = “http://mautic.sXXXXXXXXXets.de/api/”;

if ($auth->accessTokenUpdated()) {
    $this->Template->auth = $auth;
    $accessTokenData = $auth->getAccessTokenData();
}

$leadApi    = MauticMauticApi::getContext(
    "leads",
    $auth,
    $apiUrl
);

$this->Template->leads = $leadApi->getList();

$lead = $leadApi->create(array(
    'ipAddress' => $_SERVER['REMOTE_ADDR'],
    'firstname' => "Test1",
    'lastname'  => "Test2",
    'email'     => "test@test.de",
 
));
$this->Template->leads = $lead;
//$this->Template->leads = $leadApi->get(4);

}


If other information is needed i will post it as fast as it is possible.
Already thanks for your help

Hello Guys,

i’m actually integrating the mautic API into a website.
After some hours i got it so far that i get a access_token and can get a list of all leads.
But when i try to get a lead by id or try to create a lead i get the following back in my array:

Array ( [error] => Array ( [code] => 403 [message] => You do not have access to the requested area/action. ) )

Down below is my actual code:

use MauticAuthApiAuth;
use MauticMauticApi;
$rootdir = $_SERVER['DOCUMENT_ROOT'];
include $rootdir . '/lib/AutoLoader.php';

$settings = array(
    'baseUrl'          => 'http://mautic.sXXXXXXXXXets.de',
    'version'          => 'OAuth2',
    'clientKey'        => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'clientSecret'     => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'callback'         => 'http://XX.XXXXXt.de/mautic/mXXXXXuth.html'
); 

$auth = ApiAuth::initiate($settings);

if ($auth->validateAccessToken()) {
    $apiUrl = "http://mautic.sXXXXXXXXXets.de/api/";

    if ($auth->accessTokenUpdated()) {
        $this->Template->auth = $auth;
        $accessTokenData = $auth->getAccessTokenData();
    }
   
    $leadApi    = MauticMauticApi::getContext(
        "leads",
        $auth,
        $apiUrl
    );
    
    $this->Template->leads = $leadApi->getList();
    
    $lead = $leadApi->create(array(
        'ipAddress' => $_SERVER['REMOTE_ADDR'],
        'firstname' => "Test1",
        'lastname'  => "Test2",
        'email'     => "test@test.de",
     
    ));
    $this->Template->leads = $lead;
    //$this->Template->leads = $leadApi->get(4);
}

If other information is needed i will post it as fast as it is possible.
Already thanks for your help

Hi, any updates here?

I am exactly with the same problem.