I'm trying to send a subscribe/signup request to mailchimp using C#. Now I was able to send it correctly but I needed to add a new parameter which is the INTERESTS field. I have a hard time looking for a sample can anyone please help me on this. Right now I have this as parameter for subscribing
var subscribeRequest = new
{
email_address = subscriber.Email,
status = subscriber.Status,
merge_fields = new
{
FNAME = subscriber.MergeField.FName,
LNAME = subscriber.MergeField.LName,
COUNTRY = subscriber.MergeField.Country
}
};
var requestJson = JsonConvert.SerializeObject(subscribeRequest);
return requestJson;
Now how do I add the Interests parameter here? Below are the ID's that I will be using
Interest ID = 4bc11d46dc
Category ID = b2602901cd
Options 1 = a6c2aa3f6c
Option 2 = 7466ab2eb9
Option 3 = 135cd6f22d
Now I have 3 option under this interest group. I would only like to set the first option to be true so how do I do this?
I tried something like this but it's not correct. Really appreciate any help
var subscribeRequest = new
{
email_address = subscriber.Email,
status = subscriber.Status,
merge_fields = new
{
FNAME = subscriber.MergeField.FName,
LNAME = subscriber.MergeField.LName,
COUNTRY = subscriber.MergeField.Country
},
interests = new {
"4bc11d46dc" = true
}
};
var requestJson = JsonConvert.SerializeObject(subscribeRequest);
return requestJson;
Ok found the answer. For those whose having the same issue as me, to solve this is to make your code like below
var subscribeRequest = new
{
email_address = subscriber.Email,
status = subscriber.Status,
merge_fields = new
{
FNAME = subscriber.MergeField.FName,
LNAME = subscriber.MergeField.LName,
COUNTRY = subscriber.MergeField.Country
},
interests = new {
"a6c2aa3f6c" = true // <<--- instead of using 4bc11d46dc use the value a6c2aa3f6c
}
};
var requestJson = JsonConvert.SerializeObject(subscribeRequest);
return requestJson;
The idea here is to just include the interest ID of the options. For the scenario I have 1 category that has 3 options. So to register/signup using one of the options in the category you just have to include the ID of that options and you don't need the ID of the LIST ID or the CATEGORY ID. Just the ID of one of the options will do.
To find out the id's in your list you can create a bash script and query the result as shown below
#!/bin/bash
# My first script
dc="<your data-center and can be found in the apikey after `-` character>"
apikey="<your api_key>"
listid="<your listid or audienceid>"
curl -sS \
"https://${dc}.api.mailchimp.com/3.0/lists/${listid}/interest-categories" \
--user "anystring:${apikey}"
This will give you all the categories
under that listing. Now using the categories id you retrieved from the result you can create another bash script to query the OPTION ID
within that listing-category id
as shown below
#!/bin/bash
# My first script
dc="<your data-center and can be found in the apikey after `-` character>"
apikey="<your api_key>"
listid="<your listid or audienceid>"
categoryid="<your categoryid found from previous bash script>"
curl -sS \
"https://${dc}.api.mailchimp.com/3.0/lists/${listid}/interest-categories/${categoryid}/interests" \
--user "anystring:${apikey}"
This will give you the ID
of the option for your list-categories. Now using the ID's from this result you can add it under the interests
parameter when sending the subscribe request as shown in the code above.
Hope this will guide anyone having a problem please give a thumbs up if you found this helpful. Will post the code or script if ever you want a copy of how I did it in C#
Reference:
https://newbedev.com/can-you-get-a-mailchimp-interest-group-id-without-using-the-api