简体   繁体   中英

How to get unsubscribe URL from Mailchimp list ID API

I'm struggling to get the unsubscribe URL from the Mailchimp API. I've managed to find the subscribe URL by accessing get("lists/{$list_id}/signup-forms"); which returns the following json. However, there's no unsubscribe URL displaying and I can't think of other actions to call apart from signup-forms.

When checking the unsubscribe link in the mailchimp account manually, both the subscribe and unsubscribe links look identical apart from the /subscribe. So my next approach would be to get the subscribe_url_long and replace the string subscribe with unsubscribe .

Unless anyone knows a way of accessing the the property from the list ID?

    {
   "subscribe_url_long": "https://live.us3.list-manage.com/subscribe?u=XXXXX&id=XXXXX",
    }

If anyone wonders how I fixed this, I managed to grab the following code from the API using the code blow:

public
    function get_unsubscribe_url(string $list_id, array $fields = []) {
        $list = $this->get("lists/{$list_id}");
        $subscribe_url = $list['subscribe_url_long'];
        $unsubsribe_link = str_replace('subscribe', 'unsubscribe', $subscribe_url);
        return $unsubsribe_link;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM