Get and update a user by Username

So the APi doco is sparse on getting and setting a user by username. We have an issue where some of our usernames are all numbers and the API is treating them a UserID and not a user name. 

Getting a User

I can use this code to get a user in c#, but I am appending ?username=## to the url. So it seems like a hack

public dynamic GetTelligentUser(string username)
{
    ServicePointManager.Expect100Continue = false;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    var host = new ClientCredentialsRestHost(
        communitySettings.Username,
        communitySettings.Endpoint,
        communitySettings.OAuthClientId,
        communitySettings.OAuthSecret);

    var response = host.GetToDynamic(2, $"user.json?username={username}", true, new RestGetOptions
    {

    });
    return response;
}

Looking at the doco (community.telligent.com/.../show-user-rest-endpoint), I should be doing it this way, but it never returns a username

public dynamic GetTelligentUser(string username)
{
    ServicePointManager.Expect100Continue = false;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    var host = new ClientCredentialsRestHost(
        communitySettings.Username,
        communitySettings.Endpoint,
        communitySettings.OAuthClientId,
        communitySettings.OAuthSecret);

    var response = host.GetToDynamic(2, "users/{username}.json", true, new RestGetOptions
    {
        PathParameters = new System.Collections.Specialized.NameValueCollection {
            { "username", username }
        }
    });
    return response;
}

Updating a user

I followed the doco ( Update User REST Endpoint ) for updating a user, but always says "User not found" or "Lookupusername is required". Doing it by user ID was easy and works fine. 

var host = new ClientCredentialsRestHost(
communitySettings.Username,
communitySettings.Endpoint,
communitySettings.OAuthClientId,
communitySettings.OAuthSecret);

var response = host.PutToDynamic(2, "users/{lookupusername}.json", true, new RestPutOptions
{
PathParameters = new NameValueCollection {
    { "lookupusername", username }
},
PostParameters = new NameValueCollection()
{
    { "_ProfileFields_Address", profileData.ContactInfo.Address },
    { "_ProfileFields_City", profileData.ContactInfo.City },
    { "_ProfileFields_Country", profileData.ContactInfo.Country },
    { "_ProfileFields_Email", profileData.ContactInfo.Email },
    { "_ProfileFields_First_Name", profileData.ContactInfo.FirstName },
}

});

return response;



fix code
[edited by: Chris Auer at 10:01 PM (GMT 0) on Tue, Mar 2 2021]
Parents
No Data
Reply Children
  • The way I read it, Chris, (without trying it myself) is that you may need both lookupUsername and username to make a Username change.

    Lookupusername string Either Id or Lookupusername is required. Optional
    Username string Required if changing the username. Optional
  • Former Member
    0 Former Member in reply to Chris Auer

    Are you having an issue with the Update endpoint for usernames that are not numbers only?  That should work fine. 

    While you are defining the path like:

    var response = host.PutToDynamic(2, "users/{lookupusername}.json", true, new RestPutOptions
    {
    PathParameters = new NameValueCollection {
    { "lookupusername", username }
    },

    The system just receives users/12345.json.  It has no idea you called that variable lookupusername.  It just sees the integer value and assumes its a userId.