// Get contact Id by email and update it
string api = "API_KEY";
string emailAddress = args[1].ToLower();
IRestResponse response = null;
IRestClient client = new RestClient("https://api.hubapi.com/");
IRestRequest request = new RestRequest("contacts/v1/contact/email/{email}/profile/", Method.PUT);
request.AddUrlSegment("email", emailAddress);
request.AddQueryParameter("hapikey", api);
var body = new
{
properties = new[]
{
new {property = "firstname", value = "Brendan" }
}
};
request.AddJsonBody(body);
response = client.Execute(request);
My code is above. I cannot get the POST /contacts/v1/contact/email/:email/profile endpoint to work for me. I am using C#. Any advice is greatly appreciated.
1. I noticed that you're missing the content type: application/json. Could you try adding that and see if it works?
2. If it doesn't, you might want to try changing your code to use something like this:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
user = "Foo",
password = "Baz"
});
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}