Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use Mautic API after manual install #177

Open
gbard opened this issue Oct 20, 2018 · 8 comments
Open

Unable to use Mautic API after manual install #177

gbard opened this issue Oct 20, 2018 · 8 comments

Comments

@gbard
Copy link

gbard commented Oct 20, 2018

Hello,

I struggled to use Mautic's API since I couldn't use Composer to install the API (hosted on a shared server with limited ressources). I followed the instructions to install it manually but I had errrors about missing librairies and functions. It was like if the /vendor/autoload.php was not loading all required librairies.

I was finally able to get it to work and I thought it could help some people having the same issue if I posted my source code. I'm using BasicAuth for permanent authentification.

<?php

	//LOADING REQUIRED LIBRAIRIES (MAKE SURE TO POINT TO THE RIGHT FOLDER, ON MY SERVER I UPLOADED THE API FILES FROM GITHUB TO THE /LIB DIRECTORY) - ORDER MATTERS, MAKE SURE IT'S LOADED IN THIS ORDER

	require_once __DIR__ . '/lib/MauticApi.php'; 
	require_once __DIR__ . '/lib/Psr/Log/LogLevel.php';
	require_once __DIR__ . '/lib/Psr/Log/LoggerInterface.php';
	require_once __DIR__ . '/lib/Psr/Log/AbstractLogger.php';
	require_once __DIR__ . '/lib/Psr/Log/NullLogger.php';
	require_once __DIR__ . '/lib/Psr/Log/LoggerAwareInterface.php';
	require_once __DIR__ . '/lib/QueryBuilder/QueryBuilder.php';
	require_once __DIR__ . '/lib/QueryBuilder/WhereBuilder.php';
	require_once __DIR__ . '/lib/Api/Api.php';
	require_once __DIR__ . '/lib/Api/Assets.php';
	require_once __DIR__ . '/lib/Api/CampaignEvents.php';
	require_once __DIR__ . '/lib/Api/Campaigns.php';
	require_once __DIR__ . '/lib/Api/Categories.php';
	require_once __DIR__ . '/lib/Api/Companies.php';
	require_once __DIR__ . '/lib/Api/CompanyFields.php';
	require_once __DIR__ . '/lib/Api/ContactFields.php';
	require_once __DIR__ . '/lib/Api/Contacts.php';
	require_once __DIR__ . '/lib/Api/Data.php';
	require_once __DIR__ . '/lib/Api/Devices.php';
	require_once __DIR__ . '/lib/Api/DynamicContents.php';
	require_once __DIR__ . '/lib/Api/Emails.php';
	require_once __DIR__ . '/lib/Api/Files.php';
	require_once __DIR__ . '/lib/Api/Focus.php';
	require_once __DIR__ . '/lib/Api/Forms.php';
	require_once __DIR__ . '/lib/Api/Leads.php';
	require_once __DIR__ . '/lib/Api/Segments.php';
	require_once __DIR__ . '/lib/Api/Lists.php';
	require_once __DIR__ . '/lib/Api/Messages.php';
	require_once __DIR__ . '/lib/Api/Notes.php';
	require_once __DIR__ . '/lib/Api/Notifications.php';
	require_once __DIR__ . '/lib/Api/Pages.php';
	require_once __DIR__ . '/lib/Api/Points.php';
	require_once __DIR__ . '/lib/Api/PointTriggers.php';
	require_once __DIR__ . '/lib/Api/Reports.php';
	require_once __DIR__ . '/lib/Api/Roles.php';
	require_once __DIR__ . '/lib/Api/Smses.php';
	require_once __DIR__ . '/lib/Api/Stages.php';
	require_once __DIR__ . '/lib/Api/Stats.php';
	require_once __DIR__ . '/lib/Api/Tags.php';
	require_once __DIR__ . '/lib/Api/Themes.php';
	require_once __DIR__ . '/lib/Api/Tweets.php';
	require_once __DIR__ . '/lib/Api/Users.php';
	require_once __DIR__ . '/lib/Api/Webhooks.php';
	require_once __DIR__ . '/lib/Exception/AbstractApiException.php'; 
	require_once __DIR__ . '/lib/Exception/ActionNotSupportedException.php';
	require_once __DIR__ . '/lib/Exception/AuthorizationRequiredException.php'; 
	require_once __DIR__ . '/lib/Exception/ContextNotFoundException.php';
	require_once __DIR__ . '/lib/Exception/IncorrectParametersReturnedException.php';
	require_once __DIR__ . '/lib/Exception/RequiredParameterMissingException.php';
	require_once __DIR__ . '/lib/Exception/AbstractApiException.php';
	require_once __DIR__ . '/lib/Exception/UnexpectedResponseFormatException.php';
	require_once __DIR__ . '/lib/Response.php';
	require_once __DIR__ . '/lib/Auth/AuthInterface.php'; 
	require_once __DIR__ . '/lib/Auth/ApiAuth.php'; 
	require_once __DIR__ . '/lib/Auth/AbstractAuth.php'; 
	require_once __DIR__ . '/lib/Auth/OAuth.php'; 
	require_once __DIR__ . '/lib/Auth/BasicAuth.php'; 

	// INITIALIZING AUTH OBJECT
	use Mautic\Auth\ApiAuth;
	
	$initAuth = new ApiAuth();
	
	// CONNECTION PARAMETERS
	$apiUrl  = 'https://your.domain/mautic/'; // Your Mautic instance root directory
	$settings = array(
		'userName'   => 'api',  // Create a new user (regular user)
		'password'   => 'password'
	);
	
	$auth = $initAuth->newAuth($settings, 'BasicAuth');

	// USING MAUTIC'S API
	use Mautic\MauticApi;

	$api = new MauticApi();
	
	$contactApi = $api->newApi('contacts', $auth, $apiUrl);
	
	// IN THIS EXAMPLE I'M CHANGING THE OWNER OF THE CONTACT WITH THE ID = 999 TO THE USER WITH THE ID = 2
	$updatedData = array(
		'owner' => $_GET['value']
	);
	$response = $contactApi->edit('999', '2');
?>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@ActiveOrganisation
Copy link

This is a lifesave (I think) - - - but I don't have any of these files in my download from Github:

require_once DIR . '/lib/Psr/Log/LogLevel.php';
require_once DIR . '/lib/Psr/Log/LoggerInterface.php';
require_once DIR . '/lib/Psr/Log/AbstractLogger.php';
require_once DIR . '/lib/Psr/Log/NullLogger.php';
require_once DIR . '/lib/Psr/Log/LoggerAwareInterface.php';

I know it's been a while since you posted... but any ideas??

@RCheesley
Copy link
Member

@ActiveOrganisation I have an API Library instance set up with DDEV (total game changer, very easy to set up!), and I find these PSR resources in the /vendor/psr/log folder.

Maybe something has changed recently and the info is out of date?

@cyberphen
Copy link

So, no one's gonna tell that you cannot create a custom accessible .php file in mautic's folder?

@cyberphen
Copy link

I still can't figure out how to use the api library. Did everything hundreds of posts suggests. Including this one. Is there any where I can find a guide for absolute dummies? By absolute dummy I mean that I don't even know .htaccess file.

@ActiveOrganisation
Copy link

I think the:

require_once DIR . '/lib/Psr/Log/LogLevel.php';
require_once DIR . '/lib/Psr/Log/LoggerInterface.php';
require_once DIR . '/lib/Psr/Log/AbstractLogger.php';
require_once DIR . '/lib/Psr/Log/NullLogger.php';
require_once DIR . '/lib/Psr/Log/LoggerAwareInterface.php';

MUST be being loaded from somewhere other than the Mautic files 'cos it's not there as far as I can see.

@RCheesley - I am really sorry but I am not as technical any more as I used to be. Feeling a bit out of it. Does DDEV use Composer?? I looked at their promo video but it was just generic sales malarky and didn't really tell me anything useful.

Also.. I would love to connect with you properly because I want to contribute to the Mautic Joomla plugin and the developer docs but I am feeling I need someone to checkup or checkin with before taking the leap. I haven't used Git for many many years and I don't want to screw it up.

@cyberphen - I feel your pain. I am trying to step up and raise my game rapidly so I can do a complete help file on this (i.e. how to use Mautic API on shared hosting without composer)... AND, what I have found out is that, often, you might not need it. Just use the cURL options. If you join the Mautic forum and go here: (https://forum.mautic.org/t/documentation-disaster/18201/3) there is some basic info...

@cyberphen
Copy link

cyberphen commented Mar 3, 2021

Hi,
@ActiveOrganisation
I finally figured out the API and would really like to help in filling the holes in the documentation. Just tell me how I can help? Also, I guess it is a bug or something that API does not work when we include the autoloader file.

@ActiveOrganisation
Copy link

ActiveOrganisation commented Mar 3, 2021

Yeah... I am hectic with work at the moment but I am keen to learn how I can contribute... There are lots of resources. There is even a knowledge base (which seems to be beautifully hidden)... https://kb.mautic.org/ . The way it works is that you head to the GitHub location for the developer docs (https://github.com/mautic/developer-documentation) . Do a Pull Request.. And, (I think - not sure) you then create a new branch... But, I am not really sure how to then get that approved and push it back into play. I am a bit rusty on these things. @RCheesley knows. :-)

@RCheesley
Copy link
Member

RCheesley commented Mar 4, 2021

Hi folks,

We do have quite a lot of resources to help you get started. Please take a look at https://contribute.mautic.org/contributing-to-mautic/developer as a starting point. Basically you will always need to make a personal fork (Please try to make this under your personal account rather than a company, as that allows maintainers to push changes if we need to) and then make a PR from that fork to the main repo.

Recommend that you join us on Slack at https://mautic.org/slack and head over to #t-product if you would like to get involved in contributing, that is where we coordinate all of the work, and where the team can help you if you get stuck with any aspect!

In terms of documentation we have #t-education on Slack which is the education team. You can make PR's to the Developer Documentation and the End User Documentation.

Please take a look at our docs for contributing and our Style Guide. These apply mostly to the End User docs but hopefully gives some pointers!

We definitely need help to improve the developer docs, it's probably the most neglected part of our documentation and could certainly do with some TLC!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants