简体   繁体   中英

MailChimp integration with asp.net

I am facing a issue with mailChimp, I make a PUT call with HttpWebRequest for unsubscribing a user from the list, it works fine but the same thing I had done with POST call with status as unsubscribed then it also works. So which call should I make for unsubscription?

Example code with mailChimp Api key in added in HttpWebRequest headers:

string subscriberEmail = "XXXXXX";
//Create JSON Object for sending to MailChimp

var subscribeRequest = new
{
    status = "unsubscribed",
    email_address = subscriberEmail, //E-Mail
 };
var requestJson = serializer.Serialize(subscribeRequest);
HttpWebRequest httpWebRequest =(HttpWebRequest)HttpWebRequest.Create(https://XXX.api.mailchimp.com/3.0/lists/XXXXXX/members");
httpWebRequest.Method = "POST";    
httpWebRequest.ContentType = "text/json";                               
httpWebRequest.Accept = "text/json";

Rather than a hard-rule on what to choose, here is an explanation on why both Verbs work.

A lot of API providers support the same operations for both the PUT and POST verb.

In pure REST terms, these verbs have specific guidelines of POST for creating new resources and PUT for updating resources.

But in most real-world APIs, the lines blur between following 100% REST guidelines vs. providing action oriented APIs. eg (Unsubscribe, Cancel etc.)

In that, it really doesn't matter if you use POST or PUT and hence a lot of API providers provide support for both. Internally they tend to always go through the same code path, and hence you should see the same behavior in both cases.

When both PUT and POST are available for action oriented APIs (unsubscribe, cancel etc.) I have seen folks preferring the POST Verb, since it is more intuitive and natural on a non-read-only API.

But there is really no hard rule, so whatever you decide stick to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM