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
  • Hi  , I just did a quick test like this

    In my case, the username is "John.Reynolds"

    First I tried "user" endpoint with Username Parameter

    /api.ashx/v2/user.json?Username=John.Reynolds

    => Returned successful user object as JSON

    Next I tried "users" endpoint with Username Parameter

    /api.ashx/v2/users.json?Username=John.Reynolds

    => Returned error below

    {
    "Info": [],
    "Warnings": [],
    "Errors": [
    "Username is not a valid parameter."
    ]
    }
    So I would try "user" not "users" for getting the user.
    Setting should be easier because then you have the Verint ID to update back to the community and that would be the better parameter to update.

     

  • Thanks John, using user instead of Users in Telligent API doco code, returns a 404. So the only way I can find to get a user by username is by calling the username, is by calling the url /api.ashx/v2/user.json?Username=John.Reynolds. 

    But I cant get the documented way to get and most importantly Update the user by username.

    var host = new ClientCredentialsRestHost(
        communitySettings.Username,
        communitySettings.Endpoint,
        communitySettings.OAuthClientId,
        communitySettings.OAuthSecret);
    
    var response = host.GetToDynamic(2, "user/{username}.json", true, new RestGetOptions
    {
        PathParameters = new System.Collections.Specialized.NameValueCollection {
            { "username", username }
        }
    });
    return response;

Reply
  • Thanks John, using user instead of Users in Telligent API doco code, returns a 404. So the only way I can find to get a user by username is by calling the username, is by calling the url /api.ashx/v2/user.json?Username=John.Reynolds. 

    But I cant get the documented way to get and most importantly Update the user by username.

    var host = new ClientCredentialsRestHost(
        communitySettings.Username,
        communitySettings.Endpoint,
        communitySettings.OAuthClientId,
        communitySettings.OAuthSecret);
    
    var response = host.GetToDynamic(2, "user/{username}.json", true, new RestGetOptions
    {
        PathParameters = new System.Collections.Specialized.NameValueCollection {
            { "username", username }
        }
    });
    return response;

Children