1

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

Community
  • 1
  • 1
Hyra10
  • 460
  • 2
  • 6
  • 18
  • What is the error message being returned from MailChimp? See [this section](http://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/#errors) of the docs on dealing with errors. – TooMuchPete May 31 '16 at 19:55
  • The error I am getting is 400 bad Request, but no more data to clarify the problem – Hyra10 May 31 '16 at 21:21
  • 400 Bad Request errors come with a lot more detail than that (see the doc link for an example). You'll want to figure out how to access the error response body/text to see what the error is. – TooMuchPete Jun 01 '16 at 00:46

0 Answers0