# Error 403 at creating a lead with api

**URL:** <https://forum.mautic.org/t/error-403-at-creating-a-lead-with-api/3638>\
**Category:** Product Support\
**Created:** [May 2, 2016, 10:58am UTC](https://forum.mautic.org/t/error-403-at-creating-a-lead-with-api/3638 "2016-05-02T10:58:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trambo94](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@Trambo94](https://forum.mautic.org/u/Trambo94)\
**Post date:** [May 2, 2016, 10:58am UTC](https://forum.mautic.org/t/error-403-at-creating-a-lead-with-api/3638/1 "2016-05-02T10:58:54Z")

</div>

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](http://mautic.sXXXXXXXXXets.de)’,  
‘version’ =\> ‘OAuth2’,  
‘clientKey’ =\> ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’,  
‘clientSecret’ =\> ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’,  
‘callback’ =\> ‘[http://XX.XXXXXt.de/mautic/mXXXXXuth.html](http://XX.XXXXXt.de/mautic/mXXXXXuth.html)’  
);

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

if ($auth-\>validateAccessToken()) {  
$apiUrl = “[http://mautic.sXXXXXXXXXets.de/api/](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

---

<div class="post-metadata">

**Author:** ![Trambo94](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@Trambo94](https://forum.mautic.org/u/Trambo94)\
**Post date:** [May 2, 2016, 10:58am UTC](https://forum.mautic.org/t/error-403-at-creating-a-lead-with-api/3638/2 "2016-05-02T10:58:54Z")

</div>

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:

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

Down below is my actual code:

```auto
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

---

<div class="post-metadata">

**Author:** ![marco.ultrahaus](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@marco.ultrahaus](https://forum.mautic.org/u/marco.ultrahaus)\
**Post date:** [March 2, 2017, 6:08pm UTC](https://forum.mautic.org/t/error-403-at-creating-a-lead-with-api/3638/3 "2017-03-02T18:08:27Z")

</div>

Hi, any updates here?

I am exactly with the same problem.
