PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 6, 2022

[FIXED] How to get unsubscribe URL from Mailchimp list ID API

 September 06, 2022     mailchimp, mailchimp-api-v3.0, php     No comments   

Issue

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",
    }

Solution

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;
    }


Answered By - Shaun
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing