Set status: subscribed via mailchimp api

To change a subscriber’s “status” to “subscribed” using the Mailchimp API, send a PATCH request to the lists/list id/members/{subscriber_hash} endpoint, where the list id is the ID of the list to be updated and the subscriber hash is the MD5 hash of the subscriber’s email address. The request body should include a JSON object with the desired updates, including setting the “status” field to “subscribed”.

The code below uses the curl command line tool to send a PATCH request to the Mailchimp API to update the status of a subscriber on a specific mailing list.

Here’s an example of how to use cURL:

curl –request PATCH \
–url{list_id}/members/{subscriber_hash} \
–user ‘anystring:apikey’ \
–header ‘content-type: application/json’ \
–data ‘{“status”:”subscribed”}’

Here is a list of the different options used in the command.

  • –request PATCH:
    This tells curl to use the PATCH method for the request. PATCH is used to apply partial updates to a resource on the server.
  • –url{list_id}/members/{subscriber_hash}: This is the URL of the Mailchimp API endpoint that the request will be sent to. Replace {list_id} and {subscriber_hash} with your actual values for the list and subscriber you want to update.
  • –user ‘anystring:apikey’:
    The API key and username are set in this option. The user name can be any string and the API key is provided by Mailchimp.
  • –header ‘content-type: application/json’:
    The content-type in the request tells the server that the data to be sent is in JSON format.
  • –data ‘{“status”:”subscribed”}’:
    This sets the data that will be sent with the request. In this case, it’s a JSON object containing one key-value pair: The subscriber status will be set to subscribed.

{subscriber_hash} can be replaced by the contact id, member id, or unique email id in the above request.

Check that your API key is valid, and replace usX with the server corresponding to your account.

The output of the above response will contain the member info from Mailchimp:

    "id": "34535sdfsdf7a1a",
    "email_address": "",
    "unique_email_id": "24352323d",
    "contact_id": "dfdf324234sdfsdf",
    "list_id": "234fsdfsdf",
    "_links": [
            "rel": "self",
            "href": "",
            "method": "GET",

You can UX value corresponding to your account by going into your Mailchimp dashboard. The URL will contain the domain you are looking for. The list ID can be fetched via the Settings page of the Audience dashboard.

With the response returned you can confirm that the “status” property has been updated.