# Mautic API creates lead entity with NULL values

**URL:** <https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485>\
**Category:** Mautic 5 Install/Upgrade Support\
**Created:** [April 9, 2025, 4:36pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485 "2025-04-09T16:36:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:36pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/1 "2025-04-09T16:36:37Z")

</div>

**Your software**  
My Mautic version is: 5.2.4  
My PHP version is: 8.2.20  
My Database type and version is: MariaDB 10.5.18

**Your problem**  
Using composer-based Mautic v5.2.4 (latest) and creating contacts via Mautic API endpoint:

```auto
POST https://<mautic-local-url>/api/contacts/new
Authorization: Basic <md5_encode(username:password)>
Content-Type: application/json

{"firstname": "Alexander", "lastname": "Nitsche", "email": "alexander.nitsche@t-online.de"}

```

Unfortunately, the persisted entity in db table `leads` only contains fields of value NULL except for fields `id`, `is_published`, `date_added`, `created_by` and `created_by_user`. It worked some days ago, not sure, what happened. I checked for users with restricted and also admin rights.

These errors are showing in the log: None, the server sends a 201 (Created) instead.

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:37pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/2 "2025-04-09T16:37:27Z")

</div>

While step debugging into LeadApiController.php::newEntityAction(), it seems to be that the API is using the controller to fill the request parameters into the lead form and send this form. It seems to be that the filling is not done right and the form fields remain empty.

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:37pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/3 "2025-04-09T16:37:48Z")

</div>

In \Mautic\ApiBundle\Controller\CommonApiController::processForm() the $submitParams always contain the correct request parameters, but they never make it into $form nor $entity, where the latter gets eventually persisted in the database.

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:38pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/4 "2025-04-09T16:38:09Z")

</div>

Now i become aware that the form fields like firstname etc. are missing in mautic frontend too .. huh?!

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:38pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/5 "2025-04-09T16:38:26Z")

</div>

It seems that `{% set groups = fields|keys|sort %}` in /public/app/bundles/LeadBundle/Resources/views/Lead/form.html.twig is empty and therefore no fields are rendered ..

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:38pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/6 "2025-04-09T16:38:46Z")

</div>

My `lead_fields` db table is empty and maybe that is the reason?

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:51pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/7 "2025-04-09T16:51:21Z")

</div>

I probably was to eager to reset the stage for testing ..

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 4:51pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/8 "2025-04-09T16:51:53Z")

</div>

Is there a way to recreate the default entries of the `lead_fields` table?

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 7:31pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/9 "2025-04-09T19:31:55Z")

</div>

John: Not without clearing also the rest of the tables.

---

<div class="post-metadata">

**Author:** ![alexnitsche](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexnitsche/32/12272_2.png) [@alexnitsche](https://forum.mautic.org/u/alexnitsche)\
**Post date:** [April 9, 2025, 7:32pm UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/10 "2025-04-09T19:32:08Z")

</div>

Reinstalling mautic solved the problem, thx!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [April 11, 2025, 7:32am UTC](https://forum.mautic.org/t/mautic-api-creates-lead-entity-with-null-values/35485/11 "2025-04-11T07:32:42Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
