using UserListRequest with REST API End Point

using UserListRequest with REST API End Point

This question is answered

Hi, I am trying to get a list of users but filter it by usernames using the <UserListRequest> node. But I get an 500 error saying that the
<UserListRequest> node wasn't expected.

This is the end point:
api.ashx/v2/users.xml (http://telligent.com/community/developers/w/wiki/get-users.aspx)

here is some sameple code:

HttpWebRequest request = WebRequest.Create("http://mysite.com/api.ashx/v2/users.xml") as HttpWebRequest;
request.Method = "POST";
request.Headers.Add("Rest-Method", "PUT");
string requestBody = "<request><UserListRequest>testuser</UserListRequest></request>";

byte[] bytes = Encoding.UTF8.GetBytes(requestBody);
request.ContentLength = bytes.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

using (HttpWebResponse webResponse = request.GetResponse() as HttpWebResponse)
{
using (var reader = new StreamReader(webResponse.GetResponseStream()))
{
Console.WriteLine(reader.ReadToEnd());
}
}




What should I be posting to filter by usernames correctly?

Thanks

Adam
Verified Answer
  • Adam, for getting a list of users check out this example: telligent.com/.../get-users.aspx

    You should be using GET instead of POST and you don't need to add the Rest-Method=PUT header, that is only when you are doing an update on a specific user.

    To filter by usernames: your URL, based on the example, would look something like this:

    http://mysite.com/api.ashx/v2/users.xml?usernames=testuser,nextuser,anotheruser

  • Thought I'd throw in a quick note on when to use GET and when to use POST and when to add the Rest-Method header.

    LIST: use GET, no Rest-Method header.

    SHOW: use GET, no Rest-Method header.

    CREATE: use POST, no Rest-Method header.

    UPDATE: use POST, Rest-Method header set to PUT

    DELETE: use POST, Rest-Method header set to DELETE

  • Thanks Dan, that worked a treat. It would be helpful If the examples were extended a bit to include things like optional paramaters passed in.

    Thanks for your help anyway.

All Replies
  • Adam, for getting a list of users check out this example: telligent.com/.../get-users.aspx

    You should be using GET instead of POST and you don't need to add the Rest-Method=PUT header, that is only when you are doing an update on a specific user.

    To filter by usernames: your URL, based on the example, would look something like this:

    http://mysite.com/api.ashx/v2/users.xml?usernames=testuser,nextuser,anotheruser

  • Thought I'd throw in a quick note on when to use GET and when to use POST and when to add the Rest-Method header.

    LIST: use GET, no Rest-Method header.

    SHOW: use GET, no Rest-Method header.

    CREATE: use POST, no Rest-Method header.

    UPDATE: use POST, Rest-Method header set to PUT

    DELETE: use POST, Rest-Method header set to DELETE

  • Thanks Dan, that worked a treat. It would be helpful If the examples were extended a bit to include things like optional paramaters passed in.

    Thanks for your help anyway.