# Getting started with Mautic API

**URL:** <https://forum.mautic.org/t/getting-started-with-mautic-api/20669>\
**Category:** Product Support\
**Tags:** mautic-3, mautic-4\
**Created:** [August 31, 2021, 9:49pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669 "2021-08-31T21:49:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [August 31, 2021, 9:49pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/1 "2021-08-31T21:49:06Z")

</div>

**Your software**  
My Mautic version is: 3.3.3  
My PHP version is: 7.4  
My Database type and version is: MySQL

**Your problem**  
My problem is: Not really a problem, just need some direction…

I think I need the Mautic API to have more flexible integration with my websites/databases on the same server - or will the API take a lot of resources, cause problems, security issues? Should I upgrade to version 4 first; does it have API “built in” or other relevant improvements?

[There are different options to install the API library](https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api):

> **Install the Mautic API with Composer.** API library is at [Packagist](https://packagist.org/packages/mautic/api-library). So simple `composer require mautic/api-library` command will installation of the library to your project for you. Composer will also automatically include the library to your project.

That is kinda awful…

Does it matter where I run `composer require mautic/api-library`? Should I cd to my mautic folder or will Composer magically dump the files in the right place? Does it matter if I run as root or user?

Composer option is way too scary for me, so let’s try the second option:

> Install by git clone
> 
> 1. Go to your project folder where you want to place Mautic API library to be. For example:  
> `cd /var/www/html/myproject`
> 2. Run git clone to this folder  
> `git clone git@github.com:mautic/api-library.git .`

That looks like a better option, but the [knowledge base gives another command](https://kb.mautic.org/knowledgebase/development/what-is-mautics-api):

> git clone `mautic-api-library`

Which is it? Is one old, the other current? Would they both work? Would one mess up my installation?

**Edit:** I tried Git clone, but get ‘fatal: repository ‘mautic-api-library’ does not exist’ and even worse ‘fatal: destination path ‘.’ already exists and is not an empty directory’ for the version on the developer blog.

Safest solution would be to just download and upload the files:

> **Copy from ZIP package** : Download the library from [mautic-api-library-zip](https://github.com/mautic/api-library/archive/master.zip). Extract the package to some temporary location. Copy the /lib folder to your project.

But the link to the zip is 404 on both knowledge base and developer blog.

I’ll continue with this in the morning…

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 1, 2021, 1:52pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/2 "2021-09-01T13:52:51Z")

</div>

I’ve upgraded to Mautic 4. When I now go to Settings / Configuration I can just turn on the API; no mention of having to download an API library. I guess the API is included in version 4, which is great.

Now figuring out how to use it, starting with API Credentials (Applications) in Settings. [This looks like the most up-to-date documentation](https://kb.mautic.org/knowledgebase/development/what-is-mautics-api).

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [September 1, 2021, 3:10pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/3 "2021-09-01T15:10:22Z")

</div>

Hey there!  
The setting to turn on the API has always been there. It’s not something new with Mautic 4.

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 1, 2021, 4:03pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/4 "2021-09-01T16:03:31Z")

</div>

Have you seen my previous post on the dead links and other BS in your documentation about the API?

[I guess the most up-to-date Mautic API documentation is here?](https://developer.mautic.org/?php#oauth-2)

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [September 2, 2021, 11:27am UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/5 "2021-09-02T11:27:01Z")

</div>

You don’t need to api library to use the api  
BS is a really harsh word, it almost sounds like someone claims something works and nothin works.  
This is not the case.  
You will need a lot of patience with Mautic.  
We try to help you here with free support for this free product.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [September 2, 2021, 11:29am UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/6 "2021-09-02T11:29:19Z")

</div>

> [@modifiedcontent](#):
>
> Does it matter where I run `composer require mautic/api-library` ? Should I cd to my mautic folder or will Composer magically dump the files in the right place? Does it matter if I run as root or user?

It seems, that you don’t fully understand how to use composer or don’t understand how it works.  
I suggest to use this great tutorial:

[![](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/4/4ac723c96281d29dbc01b8c63b440033b75c5aab.jpeg "Composer Tutorial Part 1 - How to use Composer") ](https://www.youtube.com/watch?v=I6wm15OWyqg)

If you use composer in the wrong place, your Mautic will crash  
If you use the wrong composer, your library won’t be updated (M4: Composer 2, M2,3: Composer 1)

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 3, 2021, 12:01pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/7 "2021-09-03T12:01:43Z")

</div>

> You don’t need to api library to use the api

@joeyk @silavapi, so why does your documentation say that you do need a library for the API, with dead links and incomplete, badly written instructions that don’t work?

> … you don’t fully understand how to use composer …

I don’t want to use Composer. The promise of Composer is that it makes things easy because it “takes care of everything for you”, but as you indicate, if you “use Composer wrong” stuff crashes and breaks. I prefer to just upload/install files manually. Also, my server and PHP etc. is managed with EasyApache (cPanel); won’t Composer conflict with that?

**Edit:** I watched the Composer tutorial video. It still does not answer the question whether I should run the Composer command from the documentation as root or as user and whether I should cd to the Mautic directory first or run it somewhere else. They guy from the video even mentions he only knows Windows, does not know how Composer works on Linux.

Is there up-to-date documentation how to use the Mautic API anywhere?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [September 3, 2021, 12:18pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/8 "2021-09-03T12:18:23Z")

</div>

I try to answer you to the best of my knowledge:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/1/1aae01f2cc1d33eb78c95fd6fe928b5a46ecbe25.jpeg)

Once you clicked you see this:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/4/428dff189c6711528c67059fafebb76ce7a6d9f2.png)

Make sure you are super patient, and the documentation will show:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/9/90b0dae064dbb8a75ae045dd7a8327473e31cc32.png)

Here you can read about all kind of integrations depending on your skill levels.

The API library will speed up development in certain circumstances, but most of the time you are okay using webhooks. Maybe someone wrote, that API library is needed, which is true in certain situations. I’m not sure what you want to do, so it’s really hard to give an advise.

**Couple more tips:**

1. Google is your friend
2. There are really nice people here. The are nice if you are nice.
3. It’s an open source project. Most of us are not paid or compensated for being here. We are just nice. And we are happy about your success.

So for example if you ask:  
How can I send a contact to Mautic from my PHP script, then people will throw scripts at you in no time.

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 3, 2021, 1:31pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/9 "2021-09-03T13:31:31Z")

</div>

I had seen this documentation. [It says I need to install a PHP API library, with a dead link](https://developer.mautic.org/#php-library). Is this PHP library included in Mautic 4?

Some Google results for ‘Mautic API’ are these, with the same dead links:

[How to Use the Mautic Rest API](https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api)  
[What’s Mautic’s API?](https://kb.mautic.org/knowledgebase/development/what-is-mautics-api)  
[Github Mautic API Library](https://github.com/mautic/api-library)

There is a lot of information on authentication with OAuth 1.0a and OAuth 2 or BasicAuth. I think Mautic 4 only has OAuth 2?

I am trying to create a form on my non-Mautic website that posts/updates data to both Mautic and a webinar service - Demio via their API, have that part sorted out.

I guess I should use something like this in my non-Mautic site:

`\<?php  
use Mautic\MauticApi;  
use Mautic\Auth\ApiAuth;

// $initAuth-\>newAuth() will accept an array of OAuth settings  
$settings = array(  
‘baseUrl’ =\> ‘[https://your-mautic.com](https://your-mautic.com)’,  
‘version’ =\> ‘OAuth2’,  
‘clientKey’ =\> ‘5ademokeysdfa6sfas5fas6asdf8’,  
‘clientSecret’ =\> ‘adfdemosecretf3as4f5sf6asfasf97dd’,  
‘callback’ =\> ‘[https://your-callback.com](https://your-callback.com)’  
);

// Initiate the auth object  
$initAuth = new ApiAuth();  
$auth = $initAuth-\>newAuth($settings);  
$apiUrl = “[https://your-mautic.com](https://your-mautic.com)”;  
$api = new MauticApi();  
$contactApi = $api-\>newApi(“contacts”, $auth, $apiUrl);  
$contact = $contactApi-\>get($[[contact-id]]);

…`

With this I should be able to get a contact object if I replace `$[[contact-id]]` with a contact ID? And see what’s in the result with print\_r($contact) I guess.

Github has this sample code for ‘[Editing an item](https://github.com/mautic/api-library#editing-an-item)’:

`$updatedData = [  
‘firstname’ =\> ‘Updated Name’  
];

$response = $contactApi-\>edit($contactId, $updatedData);  
$contact = $response[$contactApi-\>itemName()];

// If you want to create a new contact in the case that $contactId no longer exists  
// $response will be populated with the new contact item  
$response = $contactApi-\>edit($contactId, $updatedData, true);  
$contact = $response[$contactApi-\>itemName()];`

So I need something like this, combined with the previous sample code, to post values from my non-Mautic form to Mautic?

There is information on [how to generate API credentials here](https://docs.brainstormforce.com/how-to-get-mautic-api-credentials/). The Redirect URI is static I assume? I can’t have the form on different sites for different webinars? Or is there a way around that, maybe by adding a variable the last URL part somewhere?

Trying to make something work now and will update with my findings…

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 4, 2021, 11:29am UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/10 "2021-09-04T11:29:02Z")

</div>

Putting the following in another site’s template produces a Fatal Error: Uncaught Error: Class ‘Mautic\Auth\ApiAuth’ not found in … :

`  
use Mautic\MauticApi;  
use Mautic\Auth\ApiAuth;

// $initAuth-\>newAuth() will accept an array of OAuth settings  
$settings = array(  
‘baseUrl’ =\> ‘[https://mysite.com/mautic](https://mysite.com/mautic)’,  
‘version’ =\> ‘OAuth2’,  
‘clientKey’ =\> ‘_actual\_key\_here_’,  
‘clientSecret’ =\> ‘_actual\_secret\_here_’,  
‘callback’ =\> ‘[https://otherwebsite.com/test-webinar/](https://otherwebsite.com/test-webinar/)’  
);

// Initiate the auth object  
$initAuth = new ApiAuth();  
$auth = $initAuth-\>newAuth($settings);  
$apiUrl = ‘[https://mysite.com/mautic](https://mysite.com/mautic)’;  
$api = new MauticApi();  
$contactApi = $api-\>newApi(‘contacts’, $auth, $apiUrl);  
$contactobject = $contactApi-\>get( ‘243’ );

print\_r($contactobject);

`

My CMS is looking for Mautic\Auth\ApiAuth in the wrong place; how can I direct it to the right place? What else is wrong?

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 4, 2021, 12:11pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/11 "2021-09-04T12:11:31Z")

</div>

I’ve tried this Curl approach, based on the code that works for Demio’s API. The goal is to just change the first name for a contact in Mautic with ID 243 from a page in an external site:

`  
$mautic\_url = “[https://mywebsite.com/mautic/api/contacts/](https://mywebsite.com/mautic/api/contacts/)”;

$mautic = curl\_init($mautic\_url);

curl\_setopt($mautic, CURLOPT\_URL, $mautic\_url);  
curl\_setopt($mautic, CURLOPT\_POST, true);  
curl\_setopt($mautic, CURLOPT\_RETURNTRANSFER, true);

$headers = array(  
“baseUrl: [https://mywebsite.com/mautic](https://mywebsite.com/mautic)”,  
“version: OAuth2”,  
“clientKey: _actual\_key\_here_”,  
“clientSecret: _actual\_secret\_here_”,  
“callback: [https://othersite.com/test-webinar/](https://othersite.com/test-webinar/)”,  
“Content-Type: application/json”,  
);  
curl\_setopt($mautic, CURLOPT\_HTTPHEADER, $headers);

$mautic\_data = \<\<\<DATA  
{  
“id”: “243”,  
“firstname”: “Changedfirstname”,  
}  
DATA;

curl\_setopt($mautic, CURLOPT\_POSTFIELDS, $mautic\_data);

//for debug only!

curl\_setopt($mautic, CURLOPT\_SSL\_VERIFYHOST, false);  
curl\_setopt($mautic, CURLOPT\_SSL\_VERIFYPEER, false);

$something = curl\_exec($mautic);

curl\_close($mautic);

var\_dump($something);  
`

This produces the following error:

string(161) “{“errors”:[{“message”:“Looks like I encountered an error (error #400). If I do it again, please report me to the system administrator!”,“code”:400,“type”:null}]}”

Did that error message come from Mautic or my CMS? Is this code communicating with the API - partial success… - or still completely wrong?

How can I make this work? Is there minimum code example how to communicate with the API anywhere?

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 4, 2021, 12:26pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/12 "2021-09-04T12:26:20Z")

</div>

Trying a brute force approach; just putting this in the address bar:

[https://mysite.com/mautic/api/contacts/?clientKey=](https://mysite.com/mautic/api/contacts/?clientKey=)_actual\_key_&clientSecret=_actual\_secret_&id=243&firstname=Changedname

This results in the following:

{“errors”:[{“message”:“API authorization denied.”,“code”:401,“type”:“access\_denied”}]}

What is the minimal example to communicate with the API?

Where are the PHP API files supposed to be? I see I don’t have a folder /api/ in my Mautic installation; which files should I upload where? Or are they somewhere else under another name?

Should I include the API with a line like this - from dodgy years old online info…:

require\_once ` __DIR__ ` . ‘/lib/Mautic/MauticApi.php’;

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 5, 2021, 12:04pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/13 "2021-09-05T12:04:10Z")

</div>

Trying to use the Composer way to install the PHP API library that is apparently still required. Running the command `composer require mautic/api-library` as user, not root, from the Mautic directory, results in following error:

> No composer.json in current directory, do you want to use the one at /home/myusername/public\_html? [Y,n]?

That’s a no…

What can I try next? Should I copy a composer.json from somewhere else (?) and upload to my Mautic installation folder so Composer can work its “magic”?

**Edit:**

I copied the composer.json from the [API library on Github](https://github.com/mautic/api-library) to my Mautic folder and “simply ran” the magic Composer command again, resulting in the following error message:

> Warning from [https://repo.packagist.org](https://repo.packagist.org): Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See [Deprecating Packagist.org support for Composer 1.x](https://blog.packagist.com/deprecating-composer-1-support/)  
> Using version ^3.0 for mautic/api-library  
> Root package ‘mautic/api-library’ cannot require itself in its composer.json

**Edit2:**

First Composer update attempt with `composer self-update --stable`

> [Composer\Downloader\TransportException]  
> The “[https://getcomposer.org/versions](https://getcomposer.org/versions)” file could not be downloaded: allow\_  
> url\_fopen must be enabled in php.ini (https:// wrapper is disabled in the s  
> erver configuration by allow\_url\_fopen=0  
> failed to open stream: no suitable wrapper could be found)

**Edit3:**

After enabling allow\_url\_fopen, Composer self-update runs into permission errors. So this update has to be run as root? Composer self-update to version 2.1.6 went through run as root.

**Edit4:**

After updating Composer and adding the composer.json and composer.lock from the latest Mautic package to my Mautic installation folder, running `composer require mautic/api-library` again, again as user instead of root, produces this error:

> Using version ^3.0 for mautic/api-library  
> ./composer.json has been updated  
> Running composer update mautic/api-library  
> Loading composer repositories witUpdating dependencies  
> Your requirements could not be resolved to an installable set of packages.
> 
> Problem 1  
> - Root composer.json requires mautic/core-lib ^3.0 → satisfiable by mautic/core-lib[3.x-dev].  
> - mautic/core-lib 3.x-dev requires symfony/console ~3.4.0 → found symfony/console[v3.4.0-BETA1, …, 3.4.x-dev] but the package is fixed to v4.4.26 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
> 
> Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
> 
> Installation failed, reverting ./composer.json and ./composer.lock to their original content.

**Edit5:**

Trying again with `composer require mautic/api-library --with-all-dependencies` produces the following error:

> Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 67108864 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleSetGenerator.php on line 110

Apparently Composer needs a PHP memory limit of 2G, which seems insane to me…

After eventually setting the memory limit to 3G (!), something finally went through, producing the following error:

> Your requirements could not be resolved to an installable set of packages.
> 
> Problem 1  
> - Root composer.json requires mautic/core-lib ^3.0 → satisfiable by mautic/core-lib[3.x-dev].  
> - mautic/core-lib 3.x-dev requires willdurand/oauth-server-bundle dev-release-0.0.3 → found willdurand/oauth-server-bundle[dev-master, 0.0.1] but it does not match the constraint.
> 
> Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Note that Composer is looking for packages required by mautic/core-lib 3.x-dev; I had already upgraded to Mautic 4 and am using the most recent composer.json file I could find.

**Edit6:**

Apparently Mautic is [doubling down on Composer](https://www.mautic.org/blog/developer/managing-mautic-with-composer). There is command `composer update mautic/core --with-dependencies` that looks usable for my situation and maybe I can find an updated composer.json here somewhere?

`composer update mautic/core --with-dependencies` also requires 3G+ memory in PHP and produces the same errors as before:

> Loading composer repositories with package information  
> Package “mautic/core” listDependency “composer/installers” is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.  
> Dependency “symfony/var-dumper” is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.  
> Updating dependencies  
> Your requirements could not be resolved to an installable set of packages.
> 
> Problem 1  
> - Root composer.json requires mautic/core-lib ^3.0 → satisfiable by mautic/core-lib[3.x-dev].  
> - mautic/core-lib 3.x-dev requires willdurand/oauth-server-bundle dev-release-0.0.3 → found willdurand/oauth-server-bundle[dev-master, 0.0.1] but it does not match the constraint.

Note that contrary to these warnings, I already had `--with-all-dependencies` in the command.

**Edit7:**

[Does it have something to do with this bug?](https://github.com/mautic/mautic/issues/9557) [Same bug here](https://gitmemory.com/issue/mautic/mautic/9557/786726834) - the only page that comes up if you google “willdurand/oauth-server-bundle dev-release-0.0.3”.

@silavapi had answered this bug with ‘Please ensure that you are using Composer 1 - we will not be supporting Composer 2 until Mautic 4.’ As you can see above, Composer 1 didn’t work; we are now on Composer 2 with Mautic 4.

Where is ‘willdurand/oauth-server-bundle dev-release-0.0.3’ required? I don’t see it in the [composer.json for Mautic 4](https://raw.githubusercontent.com/mautic/mautic/4.x/composer.json) and can’t find it anywhere in files in my Mautic installation. If I knew where that requirement came from I could try if changing it to 0.0.1 would fix this error.

[willdurand/oauth-server-bundle](https://packagist.org/packages/willdurand/oauth-server-bundle) is apparently a ‘Server side implementation of the OAuth 1.0 protocol’. OAuth 1.0 is no longer in Mautic 4. Why is Composer even requiring this?

willdurand/oauth-server-bundle 0.0.3 is required by ‘mautic/core-lib 3.x-dev’. What is ‘mautic/core-lib 3.x-dev’ and should it be in Mautic 4?

**Edit8:**

Tried again with `composer update mautic/core --with-all-dependencies` - note ‘all’ included. Still stalls on the same error:

> Your requirements could not be resolved to an installable set of packages.
> 
> Problem 1  
> - Root composer.json requires mautic/core-lib ^3.0 → satisfiable by mautic/core-lib[3.x-dev].  
> - mautic/core-lib 3.x-dev requires willdurand/oauth-server-bundle dev-release-0.0.3 → found willdurand/oauth-server-bundle[dev-master, 0.0.1] but it does not match the constraint.

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 18, 2021, 3:35pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/14 "2021-09-18T15:35:39Z")

</div>

@silavapi

> Hey there!  
> The setting to turn on the API has always been there. It’s not something new with Mautic 4.

Is downloading/installing the PHP API library required to use the API?

Is Composer the only way to install that PHP API library?

[Is there a fix for this bug?](https://forum.mautic.org/t/why-does-composer-require-willdurand-oauth-server-bundle-0-0-3-in-mautic-4/20835)

Is the [API documentation](https://developer.mautic.org/?php#rest-api) still valid for Mautic 4?

Is there a ‘hello world’ code example for the API anywhere?

---

<div class="post-metadata">

**Author:** ![modifiedcontent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/modifiedcontent/32/511_2.png) [@modifiedcontent](https://forum.mautic.org/u/modifiedcontent)\
**Post date:** [September 19, 2021, 8:23pm UTC](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/15 "2021-09-19T20:23:32Z")

</div>

[mzagmajster](https://forum.mautic.org/u/mzagmajster) provided a [workaround to install the PHP API library here](https://forum.mautic.org/t/for-hosts-with-no-composer-how-to-add-the-api-to-a-php-script-with-require/17380/20).

This is a working example of an API call:

> require ‘/home/username/public\_html/mautic/vendor/autoload.php’;
> 
> use Mautic\Auth\ApiAuth;  
> use Mautic\MauticApi;
> 
> $settings = [  
> ‘userName’ =\> ‘administrator’,  
> ‘password’ =\> ‘ouou79897password’,  
> ];
> 
> $initAuth = new ApiAuth();  
> $auth = $initAuth-\>newAuth($settings, ‘BasicAuth’);
> 
> $apiUrl = ‘[https://yourwebsite.com/mautic/api/](https://yourwebsite.com/mautic/api/)’;  
> $api = new MauticApi();  
> $contactApi = $api-\>newApi(‘contacts’, $auth, $apiUrl);
> 
> $id = 243;  
> $data = array(  
> ‘firstname’ =\> ‘Donnie’  
> );
> 
> // Create new a contact of ID 243 is not found?  
> $createIfNotFound = false;
> 
> $contact = $contactApi-\>edit($id, $data, $createIfNotFound);
> 
> var\_dump($contact);

Put this in a php file, run it in the browser, it will change the first name of your contact with ID 243 to ‘Donnie’.

var\_dump($contact) outputs a scary amount of stuff. How can you echo `$contact->firstname` or `$contact['firstname']`? Those example don’t work of course.

Can you get a contact by email address instead of ID? Or another field?

[There is some documentation here](https://developer.mautic.org/#edit-contact). Is there a complete list of the “options” anywhere?
