mautic / mautic/api-library

Unable to use Mautic API after manual install

Open
#177 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
205
Forks
129
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the manual-installation example in the issue, including the listed lib/ files and the MauticApi and ApiAuth entry points. Determine whether this setup should be documented in the project’s existing guidance; done means a newcomer can install the library without Composer and load the required dependencies successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.