intercom / intercom-dotnet

Intercom API client library for .NET
https://developers.intercom.io/reference
Apache License 2.0
63 stars 53 forks source link

cannot set user_id to null #88

Open choran opened 6 years ago

choran commented 6 years ago

Description

Evidence

UsersClient usersClient = new UsersClient(new Authentication(TOKEN));
User user = usersClient.View("598bd1ef1f40af9c8d64ceb0");
Console.WriteLine(JsonConvert.SerializeObject(user));
user.user_id = null;
user = usersClient.Update(user);
Console.WriteLine(JsonConvert.SerializeObject(user));
user = usersClient.View("598bd1ef1f40af9c8d64ceb0");
Console.WriteLine(JsonConvert.SerializeObject(user));

If you run the above code you will see that it does not change the suer_id

kmossco commented 6 years ago

Working on this one and it seems that somewhere where we serialize the JSON object to be sent to the Intercom servers, we are disregarding any changes to null.

If I try to run the code in the OP there I get the following payload:

"params":{"id":"5a045c938b874d2a82e7413a","email":"bobz12@example.com","avatar":{"type":"avatar"},"signed_up_at":1511349783,"last_seen_ip":"188.80.56.31","custom_attributes":{"average_monthly_spend":1500.0},"last_seen_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36","last_request_at":1511349783,"unsubscribed_from_emails":false}

Running the same setting the email to null sends the following payload:

"params":{"id":"5a045c938b874d2a82e7413a","user_id":"notyomama","avatar":{"type":"avatar"},"signed_up_at":1511349783,"last_seen_ip":"188.80.56.31","custom_attributes":{"average_monthly_spend":1500.0},"last_seen_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36","last_request_at":1511349783,"unsubscribed_from_emails":false}

That's odd, because using curl for the same user but just changing the created_at, sends a lot less params:

"params":{"id":"5a045c938b874d2a82e7413a","created_at":1234567891,"user":{"id":"5a045c938b874d2a82e7413a","created_at":1234567891}}

Figuring out where these params are being created, and validating my suspicion that the way we are creating the JSON payload is ignoring null values. I'll investigate.

kmossco commented 6 years ago

Investigated this alongside @thewheat and this isn't a trivial fix as we will have to refactor how we create the JSON payload sent to the endpoints. Postponing a fix until we get other more impactful changes out.