API Setup

Okay, I need some hand holding since I don’t usually work with APIs in my programming (trying to immerse myself in the Mautic API though).



I started by downloading the API from https://github.com/mautic/api-library and uploaded it to a folder where I want to start testing it out. I followed instructions I found on this blog. However, when I try to load the PHP page I created with the updated code from step 3.3, I get this error:

Quote:
Fatal error: Class 'ApiAuth' not found in /htdocs/path/to/file/mautic_test.php on line 28

Line 28 contains:
Code:
$auth = ApiAuth::initiate($settings);

So, it's clear I didn't include a file, but I'm really unsure which file I need to include. Any direction will help.

Okay, I need some hand holding since I don’t usually work with APIs in my programming (trying to immerse myself in the Mautic API though).

I started by downloading the API from https://github.com/mautic/api-library and uploaded it to a folder where I want to start testing it out. I followed instructions I found on this blog. However, when I try to load the PHP page I created with the updated code from step 3.3, I get this error:

Line 28 contains: $auth = ApiAuth::initiate($settings);

So, it’s clear I didn’t include a file, but I’m really unsure which file I need to include. Any direction will help.

You ran the composer install commands - does the autoload.php file exist?

I went with step 2, as I’m not sure Composer is set up on my host.

The API tester is very much a developer oriented tool, I would consider composer a requirement, or at least the easiest way of getting it running. @escopecz might be able to offer some additional notes on trying to do it without though.

If you don’t have Composer installed, the library also has an autoloader which can make sure classes get loaded in. You’ll need to call include_once '/path/to/lib/Mautic/AutoLoader.php'; in your code before trying to call the Mautic API classes.

At the top of the file, I’ve tried making the call to the file located in the Mautic install (Mautic/app/autoload.php) and I still get the same error.

Is this the correct file to link to? I couldn’t find any other files with Autoload in the name.

I also tried to install via Composer, but my host is giving me an error when I run the command from Composer to install.

Looks like we don’t include it in the repo anymore because we use composer.

To create your own autoloader you’l have to copy the contents from this file:

https://github.com/mautic/mautic-joomla/blob/master/lib/Mautic/AutoLoader.php

And create the lib/Mautic/Autoload.php file yourself, and then use the require statement to include it in your project.

I used composer, and it still says ApiAuth not found. The file exists, I can see it. I ran the install for composer as well.

Gotta use MauticAuthApiAuth and it works. Might want to update the Readme in the api-library.

Im using OAuth1a with no callback, and it says “Callback not valid”. I need to have NO Callback when using the API. I know this is possible, just don’t know how to do it with Mautic Auth…

@trops could you send a PR to the api-library repo with your suggestions?