I am trying to subscribe a client to a list, I have created a method to call mailchimp api but it is giving me bad request everytime I try, I tried calling a Get Method and it worked, I don't know what I am doing wrong I tried this one already Calling MailChimp API v3.0 with .Net
this is my code so far
try
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
var info = new Info() { email_address = "example@example.com", status = "subscribed" };
var infoJson = serializer.Serialize(info);
string url = @"https://us12.api.mailchimp.com/3.0/lists/xxxxx/members";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==");
HttpResponseMessage response = client.PostAsJsonAsync(url, infoJson).Result;
if (response.IsSuccessStatusCode)
{
//something
}
else
{
//something else
}
return Ok();
}
catch (Exception ex)
{
return InternalServerError(ex);
}
public class Info
{
public string email_address { get; set; }
public string status { get; set; }
}
Thanks for you help in advance