# acymailing/trunk/back/dynamics/sendinblue/list.php

AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress, version trunk. 74 lines.

- Page: https://pluginprobe.com/plugins/acymailing/trunk/code/back/dynamics/sendinblue/list.php
- Raw: https://pluginprobe.com/plugins/acymailing/trunk/raw/back/dynamics/sendinblue/list.php
- Modified: 2026-08-03T10:18:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/acymailing/trunk/code/back/dynamics/sendinblue/list.php#L10-L20`.

```php
<?php

class SendinblueList extends SendinblueClass
{
    public function getListExternalSendingMethod(&$listId, $mailId, $createIfNotExists = true)
    {
        $brevoLists = $this->config->get('list_sendinblue', '[]');
        $brevoLists = json_decode($brevoLists, true);

        if (!empty($brevoLists[$mailId])) {
            $listId = $brevoLists[$mailId];

            return;
        }

        if (!$createIfNotExists) return;

        $listId = $this->createList('list_for_acym_mail_'.$mailId);

        $brevoLists[$mailId] = $listId;
        $this->config->saveConfig(['list_sendinblue' => json_encode($brevoLists)]);
    }

    public function createList($name)
    {
        $data = [
            'name' => $name,
            'folderId' => intval($this->getFolderId()),
        ];

        $response = $this->callApiSendingMethod('contacts/lists', $data, $this->headers, 'POST');

        // The folder Id is saved in the config but the user removed it from Sendinblue, recreate a folder
        if (!empty($response['message']) && $response['message'] === 'Folder ID does not exist') {
            $this->config->saveConfig(['sendinblue_folder_id' => 0]);

            return $this->createList($name);
        }

        return $response['id'];
    }

    public function getFolderId()
    {
        $folderId = $this->config->get('sendinblue_folder_id', 0);
        if (!empty($folderId)) return $folderId;

        $data = [
            'name' => 'AcyMailing Integration',
        ];

        $response = $this->callApiSendingMethod('contacts/folders', $data, $this->headers, 'POST');

        // The API key may be wrong
        if (empty($response['id'])) return 0;

        $this->config->saveConfig(['sendinblue_folder_id' => $response['id']]);

        return $response['id'];
    }

    public function deleteList($mailId): bool
    {
        $listId = 0;
        $this->getListExternalSendingMethod($listId, $mailId, false);

        if (empty($listId)) return false;

        $this->callApiSendingMethod(plgAcymSendinblue::SENDING_METHOD_API_URL.'contacts/lists/'.$listId, [], $this->headers, 'DELETE');

        return true;
    }
}

```
