# Trouble creating List (Segment) Email via API

**URL:** <https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637>\
**Category:** Product Support\
**Tags:** mautic-4\
**Created:** [October 11, 2022, 3:27am UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637 "2022-10-11T03:27:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![entrepositive](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/entrepositive/32/9645_2.png) [@entrepositive](https://forum.mautic.org/u/entrepositive)\
**Post date:** [October 11, 2022, 3:27am UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/1 "2022-10-11T03:27:26Z")

</div>

**Your software**  
My Mautic version is: 4.1.2  
My PHP version is: 7.4.30  
My Database type and version is: mysql 8.0.30

**Your problem**  
My problem is:  
[Using n8n / Integromat / Make] I cannot successfully create a new ‘list’ email via the API. I’ve gotten a variety of errors, but I’m currently stuck with either “_lists: This value is not valid_,” or “_[400] Looks like I encountered an error…_”

I did successfully create a ‘template’ email from API call, however it loaded with the old email editor, and i cannot edit the email at all.

Here’s the JSON payload I’m sending in the body of the call:

```auto
{
    "isPublished": false,
    "name": "test API email",
    "subject": "API test email",
    "fromAddress": "some@email.com",
    "fromName": "Entrepositive",
    "customHtml": "<p>My HTML</p>",
    "emailType": "list",
    "lists": [
                  {
                    "id":41
                  }
            ],
    "template": "blank"
}

```

These errors are showing in the log:  
_lists: This value is not valid_

Steps I have tried to fix the problem:  
Literally, everything I can think of, plus:

- Every relevant topic in this forum
- Slack
- YouTube

**Would anyone be willing to share the JSON payload they use for a POST to create a segment/list email?**

Thank you!

EP

---

<div class="post-metadata">

**Author:** ![entrepositive](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/entrepositive/32/9645_2.png) [@entrepositive](https://forum.mautic.org/u/entrepositive)\
**Post date:** [February 6, 2023, 4:55pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/2 "2023-02-06T16:55:45Z")

</div>

Still having this problem and finding solutions on this forum and the net very limited.

Any help appreciated!

EP

---

<div class="post-metadata">

**Author:** ![abdulwahab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/abdulwahab/32/505_2.png) [@abdulwahab](https://forum.mautic.org/u/abdulwahab)\
**Post date:** [August 22, 2023, 10:11am UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/3 "2023-08-22T10:11:55Z")

</div>

@entrepositive I am also facing this issue. I try to match all values in the List array in the API call but No success. It creates a ‘template’ email (without segment) but for a ‘list’ email (email with segment), it does not works and always gives the same error :  
**lists: This value is not valid.**

@entrepositive Did you find out any solution?

@joeyk Did you try to create an email using an API call? I will recommend you to just try. I think it is a bug in API.

---

<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:** [August 22, 2023, 1:13pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/4 "2023-08-22T13:13:16Z")

</div>

Because the list is an array. Try to create it accordingly. (Sorry Im travelling cant look up the querry, but I remember. Cost me 2 days and 5 grey hair to figure out.)

---

<div class="post-metadata">

**Author:** ![abdulwahab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/abdulwahab/32/505_2.png) [@abdulwahab](https://forum.mautic.org/u/abdulwahab)\
**Post date:** [August 22, 2023, 1:30pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/5 "2023-08-22T13:30:16Z")

</div>

@joeyk thanks for the reply. I just tried the array of list as it was mentioned in the documentation. Even I tried to have the same values in Mautic to just test maybe values or ids should be the reason that it is giving the error. But it always gives same error.

There will be some trick in the array of ‘lists’, I am curious how you solved this. When ever you have time just share your findings. It will be a great help from your side.

and have a safe journey.

---

<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:** [August 22, 2023, 1:42pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/6 "2023-08-22T13:42:19Z")

</div>

Hey,  
Sorry can’t clean this up, I’m in a car, but try this:

(make sure you use the right template name)

post to:  
/api/emails/new

whisper this payload:

```
'fromName' => $fromName,
'name' => $emailName,
'subject' => iconv_mime_decode($emailSubject,0,"UTF-8"),
'language' => 'de',
'template' => 'blank',
'emailType' => 'list',
'isPublished' => 0,
'customHtml' => $htmlTemplate,
'plainText' => '',
'createdBy' => 1,
'createdByUser' => 'Joey Keller',
'category' => null,
'useOwnerAsMailer' => 0,
'lists[]' => 10,
'publishUp' => date("Y-m-d").' 14:00:00',
'publishDown' => date("Y-m-d").' 18:00:00',
'unsubscribeForm' => null

```

---

<div class="post-metadata">

**Author:** ![entrepositive](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/entrepositive/32/9645_2.png) [@entrepositive](https://forum.mautic.org/u/entrepositive)\
**Post date:** [August 22, 2023, 2:20pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/7 "2023-08-22T14:20:58Z")

</div>

I did eventually get it working. The _lists_ array input and the _customHtml_ string input both required some experimenting to get working. Hopefully this thread will provide good insight to future digital adventurers like us.

A couple key points:

- While _lists_ requires array, an id of desired list should suffice.
- customHTML will not work, you must use _customHtml_.
- The string value input to customHtml must be stringified, using _JSON.stringify(yourhtml)_.
- publishUp/Down input should be a string following format “YYYY-MM-DD HH:mm:ss” **in UTC**. Mautic will automatically convert publishUp/Down datetimes to correct timezone

I’ll post a successful request body shortly.

EDIT: Adding my JSON request body:

```auto
{
    "isPublished": false,
    "name": "some-internal-name",
    "subject": "A very catchy subject",
    "fromAddress": "me@example.com",
    "fromName": "My Name",
    "useOwnerAsMailer": false,
    "publishUp": "2023-08-24 18:30",
    "publishDown": "2023-09-01 12:00",
    "customHtml": "<!DOCTYPE html>\n<head>\n <title> \n </title>\n </head>\n<body>\n Don't forget to stringify your HTML as one string before including it in the request body.</body>",
    "utmTags": {
        "utmSource": "myUTMsource",
        "utmMedium": "email",
        "utmCampaign": "my-campaign",
        "utmContent": ""
    },
    "template": "blank",
    "emailType": "list",
    "lists": [
        1
    ]
}

```

Please note that for this example, I removed all the HTML body. ~~I also haven’t played with the date formats for publish up/down yet, nor the utm params, although those are on the agenda today, so perhaps another update will come soon~~.

EP

---

<div class="post-metadata">

**Author:** ![abdulwahab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/abdulwahab/32/505_2.png) [@abdulwahab](https://forum.mautic.org/u/abdulwahab)\
**Post date:** [August 22, 2023, 2:27pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/8 "2023-08-22T14:27:40Z")

</div>

Thank you very much @joeyk 🙂

---

<div class="post-metadata">

**Author:** ![abdulwahab](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/abdulwahab/32/505_2.png) [@abdulwahab](https://forum.mautic.org/u/abdulwahab)\
**Post date:** [August 22, 2023, 2:28pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/9 "2023-08-22T14:28:59Z")

</div>

That will be really helpful if you post request body here.  
Thanks for sharing your findings @entrepositive . 👍

---

<div class="post-metadata">

**Author:** ![entrepositive](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/entrepositive/32/9645_2.png) [@entrepositive](https://forum.mautic.org/u/entrepositive)\
**Post date:** [August 22, 2023, 3:04pm UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/11 "2023-08-22T15:04:34Z")

</div>

Updated my response above. Thanks for the reminder. @abdulwahab

---

<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:** [August 24, 2023, 3:04am UTC](https://forum.mautic.org/t/trouble-creating-list-segment-email-via-api/25637/12 "2023-08-24T03:04:59Z")

</div>

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