# I need a For Dummies guide to get the Mautic API properly configured

**URL:** <https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163>\
**Category:** Product Support\
**Created:** [June 28, 2016, 2:06pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163 "2016-06-28T14:06:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [June 28, 2016, 2:06pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/1 "2016-06-28T14:06:31Z")

</div>

The problem might be that I dont have the experience/understanding of OAuth2 or I’m just having a rough time following the available instructions; likely both. Im trying to get the Mautic API configured so that I can read/write lead information as needed.  
  
  
  
**My environment:**  
  
Mautic v1.4.0  
  
Server-based install on LAMP stack

- PHP v5.4.16  
- MySql v5.5.44-MariaDB  
- cURL enabled  
- SSL enabled/implemented  
  
Mautic status: appears fully functional  
  
  
  
**Instruction sources:**  
  
A) [https://github.com/mautic/api-library#authorization](https://github.com/mautic/api-library#authorization)  
  
 ![B)]( "B)") [https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api/](https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api/)  
  
C) [https://developer.mautic.org/?php#oauth-2](https://developer.mautic.org/?php#oauth-2)  
  
  
  
**Done so far:**  
  
~1. In Mautic UI -\> Configuration -\> API Settings:  
- API enabled: yes  
- Access token lifetime: 60  
- Refresh token lifetime: 14  
  
~2. In Mautic UI -\> API Credentials, created a new entry with:  
- Name: myapi  
- Redirect URL: [https://mydomain.com](https://mydomain.com)  
- Client ID: clientid\_123  
- Client Secret: clientsecret123  
  
~3. Downloaded a .zip of the API library from github and extracted  
  
~4. Uploaded the contents of “lib” folder to /path/to/Mautic/lib/  
  
~5. Created a file with the code to obtain an access token, as instructed via instruction source A, and saved to /path/to/Mautic/apiinit.php  
  
~6. Uploaded the contents of “apitester” folder to /path/to/Mautic/apitester/  
  
  
  
**Results:**  

1. Navigating to the file from step ~5 above results in (with and without hardcoding values for the $settings array) :  

- A server 500 error in the browser  
- The following error in my server log: PHP Fatal error: Class ‘Mautic\Auth\ApiAuth’ not found in /path/to/Mautic/apiinit.php on line 28  
  
Line 28: $auth = ApiAuth::initiate($settings);  

1. Navigating the the apitester results in the following message displayed in the browser (the expected form is not displayed at any point):  
  
{“error”:“access\_denied”,“error\_description”:“OAuth2 authentication required”}  
  
  
  
**Questions:**  
  
~1. Have I placed the contents of the “lib” and “apitester” folders in the right place on my server and, if not, where do these go?  
  
~2. Instruction source C, under Libraries -\> PHP Library, says to add the following line to the project, but doesnt specify exactly where:  
  
require\_once **DIR**. ‘/lib/Mautic/MauticApi.php’; //Which folder/file/line does this code get added to?  
  
~3. How do I resolve the two Result issues?  
  
~4. What else might I be missing or getting wrong?  
  
  
  
Sorry for the long message and thanks in advance for any help.

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [July 11, 2016, 7:47pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/2 "2016-07-11T19:47:47Z")

</div>

Somebody, haha, throw me a life raft… please

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [July 8, 2016, 11:46am UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/3 "2016-07-08T11:46:01Z")

</div>

Hello Pierre, Does my answer offer you any value?

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [July 6, 2016, 11:36am UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/4 "2016-07-06T11:36:47Z")

</div>

Anybody that was able to get API functionality up and running, your help here would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![pierre\_a](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pierre_a/32/7031_2.png) [@pierre\_a](https://forum.mautic.org/u/pierre_a)\
**Post date:** [July 6, 2016, 12:20pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/5 "2016-07-06T12:20:00Z")

</div>

Hello Steven,

Your 500 error come from Mautic or API Tester ?  
Do you have test call API from our script (without API Tester interface) ?

Best regards,  
Pierre

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [July 6, 2016, 12:32pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/6 "2016-07-06T12:32:28Z")

</div>

Hi Pierre,

The 500 error occurs when I navigate to the page on my server that has the script from this page/section: [https://github.com/mautic/api-library#authorization](https://github.com/mautic/api-library#authorization)

Is this the script you are referring to?

With that script, It appears to be a PHP error relating to a problem with this line in the script: use MauticAuthApiAuth; not being processed properly and causing this line: $auth = ApiAuth::initiate($settings); to fail and produce the error message on the server log.

Please let me know if I understood and was able to answer your question properly.

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [July 1, 2016, 12:41pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/7 "2016-07-01T12:41:36Z")

</div>

Is there anybody out there?

---

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://forum.mautic.org/u/Steven)\
**Post date:** [June 28, 2016, 2:06pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/8 "2016-06-28T14:06:31Z")

</div>

The problem might be that I dont have the experience/understanding of OAuth2 or I’m just having a rough time following the available instructions; likely both. Im trying to get the Mautic API configured so that I can read/write lead information as needed.

My environment:  
Mautic v1.4.0  
Server-based install on LAMP stack

- PHP v5.4.16
- MySql v5.5.44-MariaDB
- cURL enabled
- SSL enabled/implemented  
Mautic status: appears fully functional

Instruction sources:  
A) [https://github.com/mautic/api-library#authorization](https://github.com/mautic/api-library#authorization)  
B) [https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api/](https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api/)  
C) [https://developer.mautic.org/?php#oauth-2](https://developer.mautic.org/?php#oauth-2)

Done so far:  
~1. In Mautic UI -\> Configuration -\> API Settings:

- API enabled: yes
- Access token lifetime: 60
- Refresh token lifetime: 14  
~2. In Mautic UI -\> API Credentials, created a new entry with:
- Name: myapi
- Redirect URL: [https://mydomain.com](https://mydomain.com)
- Client ID: clientid\_123
- Client Secret: clientsecret123  
~3. Downloaded a .zip of the API library from github and extracted  
~4. Uploaded the contents of “lib” folder to /path/to/Mautic/lib/  
~5. Created a file with the code to obtain an access token, as instructed via instruction source A, and saved to /path/to/Mautic/apiinit.php  
~6. Uploaded the contents of “apitester” folder to /path/to/Mautic/apitester/

Results:

1. Navigating to the file from step ~5 above results in (with and without hardcoding values for the $settings array) :

- A server 500 error in the browser
- The following error in my server log: PHP Fatal error: Class ‘Mautic\Auth\ApiAuth’ not found in /path/to/Mautic/apiinit.php on line 28  
Line 28: $auth = ApiAuth::initiate($settings);

1. Navigating the the apitester results in the following message displayed in the browser (the expected form is not displayed at any point):  
{“error”:“access\_denied”,“error\_description”:“OAuth2 authentication required”}

Questions:  
~1. Have I placed the contents of the “lib” and “apitester” folders in the right place on my server and, if not, where do these go?  
~2. Instruction source C, under Libraries -\> PHP Library, says to add the following line to the project, but doesnt specify exactly where:  
require\_once **DIR**. ‘/lib/Mautic/MauticApi.php’; //Which folder/file/line does this code get added to?  
~3. How do I resolve the two Result issues?  
~4. What else might I be missing or getting wrong?

Sorry for the long message and thanks in advance for any help.

---

<div class="post-metadata">

**Author:** ![trops](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/trops/32/3998_2.png) [@trops](https://forum.mautic.org/u/trops)\
**Post date:** [September 29, 2016, 8:58pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/9 "2016-09-29T20:58:36Z")

</div>

I tried using the API with Mautic and finally got it working…

…but felt like I had to hack my way through. I ran the API tester and snatched the token to be used in my php backend application.

The authorization is useless from a backend system because there is no one there to fill in the authorization form!

I wanted to do things like… if a user registers an account on my site, I want to add them as a lead in mautic. This seems fairly simple…but I can’t do that without an authorization token. (again, unless I am missing something).

Im still unclear as to how to do this “properly” without having to use the API tester and grabbing the token generated.

I know this HAS to be possible without an authorization token. (one-legged OAuth?)

The new version of Mautic requires php 7 which is not running on my server and I cannot rebuild an entire box just to use Mautic…

So… I have to run another server simply for running Mautic.

Ill do a clean install (I updated my last installation and nothing worked and lost 17k leads I had created because I was running php 5.4). They are still in my database if I could figure out how to migrate…or this will be a complete loss.

Soooo…giving this another shot. I love what the Mautic guys are doing, I just really really would like to find a really simple solution for talking to Mautic without the need for a popup authorization form. That makes no sense to me unless I am making an administration system and a human is authorizing.

If I am missing something please please please let me know, this would be fantastic to have working with a simple API call.

Keep up the good work guys.  
John

---

<div class="post-metadata">

**Author:** ![trops](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/trops/32/3998_2.png) [@trops](https://forum.mautic.org/u/trops)\
**Post date:** [October 6, 2016, 8:21pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/10 "2016-10-06T20:21:05Z")

</div>

Well I “had” it working until the 2.0 update. Now I am getting token\_rejected errors and can’t seem to get past it. Im using the API on a server for an iPhone app. The app calls the server, and I wanted to communicate to Mautic to update a lead etc.

I created the OAuth1a tokens successfully, after much hacking, and now I am getting token\_rejected.

Wish I could help you, but this is the most difficult API experience I have ever come across.

---

<div class="post-metadata">

**Author:** ![javier15](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@javier15](https://forum.mautic.org/u/javier15)\
**Post date:** [October 6, 2016, 9:20pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/11 "2016-10-06T21:20:29Z")

</div>

you have to add in the subdomain folder, can yuo send the version 1.4 for review?

---

<div class="post-metadata">

**Author:** ![peyman](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@peyman](https://forum.mautic.org/u/peyman)\
**Post date:** [October 9, 2016, 3:40pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/12 "2016-10-09T15:40:21Z")

</div>

Hi  
in app/config/security.php

change ‘api’ in ‘firewalls’ to this:

```auto
'api' => [
                'pattern' => '^/api',
                'http_basic' => true,
                'fos_oauth' => false,
                'bazinga_oauth' => false,
                'mautic_plugin_auth' => false,
                'stateless' => true,
            ],
```

clear cache and you can use your admin user/pass with Basic Authentication to call all API methods

---

<div class="post-metadata">

**Author:** ![suporte.agencialink](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@suporte.agencialink](https://forum.mautic.org/u/suporte.agencialink)\
**Post date:** [October 10, 2016, 4:12pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/13 "2016-10-10T16:12:45Z")

</div>

I had the same problem too, and I ended up using curl to simulate a form post.

But I only needed to save the user info in Mautic, not the other way around.

---

<div class="post-metadata">

**Author:** ![swip](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@swip](https://forum.mautic.org/u/swip)\
**Post date:** [October 10, 2016, 4:18pm UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/14 "2016-10-10T16:18:55Z")

</div>

[quote=12698:@Steven]

- PHP v5.4.16.[/quote]  
Mautic requires 5.6 & above: [https://www.mautic.org/download/requirements/](https://www.mautic.org/download/requirements/)

---

<div class="post-metadata">

**Author:** ![micki](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/micki/32/6618_2.png) [@micki](https://forum.mautic.org/u/micki)\
**Post date:** [November 27, 2023, 2:02am UTC](https://forum.mautic.org/t/i-need-a-for-dummies-guide-to-get-the-mautic-api-properly-configured/4163/15 "2023-11-27T02:02:25Z")

</div>

I have struggled to get the api setup with basic auth for OVER A YEAR and this comment fixed my issue finally! I wish there was something I could do to promote this comment to the highest level. Thank you @peyman! I can now move on with my life!
