Mayor of the Plattenbaus
Mayor of the Plattenbaus

Reputation: 1160

How to retrieve a list address using mailjet API?

I'm trying to send some email to everyone on a mailjet list. Here's what I have so far:

public function sendToListByListName($listName, $config, $vars)
{
    //First we get the list ID from the list name stored in our local settings file.
    if (array_key_exists($listName, $this->config['lists']) && $this->config['lists'][$listName] !== null) {
        $listId = $this->config['lists'][$listName];
    } else {
        return false;
    }

    //TODO: Get the list email address (for example, [email protected]) via a mailjet API call
    $listAddress = '?? API CALL HERE ??';

    //Now we use our sendEmailTo() method to send a group email to the list
    return $this->sendEmailTo($listAddress, $config, $vars);
}

(The sendEmailTo() method is a local one that some coworkers have already defined. They are currently using it to send emails to individuals.)

I've poked around in the mailjet API documentation, and I'm having trouble finding the way to convert a list ID (like 12345) into its equivalent address (like [email protected]). I'm sure it's right in front of me. Can anyone help?

Upvotes: 0

Views: 678

Answers (1)

04FS
04FS

Reputation: 5820

https://dev.mailjet.com/reference/email/contacts/contact-list/#v3_get_contactslist_list_ID

GET /contactslist/{list_ID or list_address}

[The list_address] is displayed in the Address property of the list. The full email address will be {list_address}@lists.mailjet.com. Can be used as an alternative to list_ID.

So if you query this endpoint with a list_ID, you get a list address back that you can use as prefix for @lists.mailjet.com.

Upvotes: 1

Related Questions