Trying to correctly format the req;uired parameters for adding a new contact but can't seem to get it right. I start with a dictionary and am trying to add the lists and email_addresses as arrays before encoding and sending the request. My code looks like this:
List<string> addies = new List<string>();
addies.Add("{ 'email_address' : 'test@gmail.com' }");
Dictionary<string, string[]> info = new Dictionary<string, string[]>();
info.Add("lists", new string[]{"'id' : '1475239787' "});
info.Add("email_addresses", new string[]{"'email_address' : 'test@gmail.com'"});
request.SetHeader("Content-Type", "application/json; charset=UTF-8");
request.AddHeader("Accept", "application/json");
request.RawData = System.Text.Encoding.UTF8.GetBytes(BestHTTP.JSON.Json.Encode(info));
request.Send();
but the server returns 400.
Hello,
I expect that the cause of your error is because the JSON encoder is simply encoding your JSON objects as strings, so the API is not able to interpret them properly. I would suggest looking at the output of BestHTTP.JSON.J
Sincerely,
Tracing the Debug.Log returns
{"lists":"[{'id' : '1475239787' }]", "email_addresses":"[{'email_address' : 'test@gmail.com'}]"}
I'm trying to add an individual contact via the
Looking at the details here the culprit is definitely the JSON serializer you're using. In the sample from your debug log, I've highlighted the offending characters that are converting the arrays of lists/emails into strings.
{"lists":"[{'id' : '1475239787' }]", "email_addresses":"[{'email_address' : 'test@gmail.com'}]"}
My suggestion would be to switch to a different serializer such as Json.NET.
Please let me know if there's anything more that I can do to help!
Sincerely,