.NET Updating Member
MorneJooste opened this issue · 1 comments
MorneJooste commented
Good day,
I am trying to update a member in a list using RestSharp.
I have the following code:
var client = new RestClient("https://us4.api.mailchimp.com/3.0")
{
Authenticator = new HttpBasicAuthenticator("Basic", "MyAPIKey")
};
var request = new RestRequest("lists/MyListID/members/EmailIDToEdit", RestSharp.Method.PATCH);
request.AddJsonBody("{\"email_address\":\newemail@example.com\"}");
request.RequestFormat = DataFormat.Json;
var queryResult = client.Execute(request);
This returns status: "StatusCode: OK, Content-Type: application/json; charset=utf-8, Content-Length: -1)"
But the data was not updated.
What could the problem be?
Am I doing something wrong?
Thanks
MorneJooste commented
Do not worry I found the solution.
I am using the following code now:
internal static Member UpdateSingleMember(String memberID, String emailAddress, String fileNumber, String lastName, String status)
{
RestRequest request = new RestRequest("/lists/" + ListID + "/members/" + memberID, Method.PATCH);
request.AddJsonBody(new Subscriber() { status = status, email_address = emailAddress, list_id = ListID, merge_fields = new MergeFields() { FNUMBER = fileNumber, LNAME = lastName } });
IRestResponse queryResult = Client.Execute(request);
return JsonConvert.DeserializeObject<Member>(Client.Execute(request).Content);
}
internal class Subscriber
{
public String email_address { get; set; }
public String email_type { get; set; } = "html";
public String status { get; set; }
public String list_id { get; set; }
public MergeFields merge_fields { get; set; } = new MergeFields();
}
Where Member is a class from the Schema provided by MailChimp