# A noobie struggles with Mautic API

**URL:** <https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726>\
**Category:** Product Support\
**Created:** [September 3, 2021, 10:21pm UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726 "2021-09-03T22:21:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oguruma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/oguruma/32/1003_2.png) [@oguruma](https://forum.mautic.org/u/oguruma)\
**Post date:** [September 3, 2021, 10:21pm UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/1 "2021-09-03T22:21:03Z")

</div>

I want to start building things with the Mautic API. Specifically, I want to build something that creates/updates a user when Twilio fires a webhook at it.

First, I am confused as to whether or not I actually need to install the Mautic API code or not… There are configuration options for the API in the Mautic Dashboard, but then there is also documentation saying I need to install it.

The Mautic API installer links also seem to have some 404s…

I’m trying to follow along [Joey Keller’s “Webhook/Woocommerce” tutorial.](https://joeykeller.com/process-any-webhook-with-mautic-without-zapier/)

In it, it says to call `"https://".$loginname.":".$password."@".$siteurl."/api/contacts/new",`

In my Mautic install, there is no such directory as …/api

When I make a webhook.php following Joey’s directions, and fire it, nothing happens.

---

<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, 11:53pm UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/2 "2021-09-03T23:53:16Z")

</div>

Try to capture the response and see what the problem is. Maybe its your payload.  
Also: make sure you have api and basic auth turned on.  
You dont actually need that path, its a virtual path managed by mautic.

---

<div class="post-metadata">

**Author:** ![oguruma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/oguruma/32/1003_2.png) [@oguruma](https://forum.mautic.org/u/oguruma)\
**Post date:** [September 4, 2021, 6:19am UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/3 "2021-09-04T06:19:55Z")

</div>

In my install’s public\_html directory I made a directory called “connectors.”

/public\_html/connections has a file called twilioconnector.php

Even with the default data from the article (except for my URL and user credentials I created, still nothing happens.

API is enabled, as is HTTP basic auth.

Running twilioconnector.php in the servers CLI doesn’t return anything.

```auto
<?php
$loginname = 'apiuser';
// Loginname of your API user
$password = 'yourpasswordhere';
// This is the password of the API user
$siteurl = 'yoursiteurl.tld';
// example: mymautic.com

$email = 'captain_enterprise-d@starfleet.com';
$firstname = 'Jean-Luc';
$lastname = 'Pickard';
$tag = 'purchased';

$curl = curl_init();
// Set some options - we are passing in a user agent too here
  curl_setopt_array($curl, array(
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_URL => "https://".$loginname.":".$password."@".$siteurl."/api/contacts/new",
  CURLOPT_USERAGENT => 'Mautic Connector',
  CURLOPT_POST => 1,
// posting the payload
  CURLOPT_POSTFIELDS => array(
    'firstname' => $firstname,
    'lastname' => $lastname,
    'email' => $email,
    'tags' => $tag
  )
));
curl_exec($curl);

?>

```

---

<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 4, 2021, 7:29am UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/4 "2021-09-04T07:29:02Z")

</div>

After enabling the api, did you clear the cache?

---

<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:57pm UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/5 "2021-09-04T12:57:11Z")

</div>

@oguruma , I am also struggling [getting started with Mautic API here](https://forum.mautic.org/t/getting-started-with-mautic-api/20669/12). Have you found out the basics? Do you have a minimal example how to communicate with the API - just get the firstname from a contact by ID or something like that?

---

<div class="post-metadata">

**Author:** ![oguruma](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/oguruma/32/1003_2.png) [@oguruma](https://forum.mautic.org/u/oguruma)\
**Post date:** [September 4, 2021, 10:12pm UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/6 "2021-09-04T22:12:16Z")

</div>

Aha! That did it. I cleared the cache, and now it works when I fire it from the Mautic server’s CLI.

Now, what I am trying to figure out is how to fire a webhook at it from another source. Eventually I will have Twilio fire a Curl call at it. In the example below, I am using a Wordpress site to fire it. I verified the CURL call works by sending it to my Pipedream. Pipedream received the JSON payload, which for this example, contains only the username and email address.

I have the curl call below

```auto
	$mautic_array = [
    'username' => $userdata['user_login'],
    'email' => $userdata['user_email']
    ];

    $url = 'http://mymautic.com/connections/twilioconnector.php';

	$mautic_array_json = json_encode($mautic_array);

 $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

    curl_setopt($ch, CURLOPT_POST,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
        
          rawurlencode($mautic_array_json)    
               );
        
       

    $resp = curl_exec($ch);
    curl_close($ch);
    return json_decode($resp,true);

```

When I fire this (which happens when I create a new Wordpress user, in this case), nothing happens. Even when I just leave the “Jean-Luc” variables unchanged.

---

<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 5, 2021, 10:47am UTC](https://forum.mautic.org/t/a-noobie-struggles-with-mautic-api/20726/7 "2021-09-05T10:47:35Z")

</div>

Can u print your $resp? var\_dump($resp);
