# 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:** 1\
**Showing post:** 15

<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?

---

_[View the full topic](https://forum.mautic.org/t/getting-started-with-mautic-api/20669)._
