intercom-dotnet icon indicating copy to clipboard operation
intercom-dotnet copied to clipboard

cannot set user_id to null

Open choran opened this issue 8 years ago • 2 comments

Description

  • It is not possible to clear a user_id value using the .NET SDK
    • Setting it to null does not send the data to the API
  • curl request as expected and allows it

We support setting user_id to nil (tested it) I can understand the logic in wanting to remove user_ids from your users which we support.


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

choran avatar Nov 24 '17 12:11 choran

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":"[email protected]","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 avatar Dec 05 '17 21:12 kmossco

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.

kmossco avatar Dec 19 '17 17:12 kmossco