0

I am writing a very small C# console app and I am making an HttpWebRequest to get the list items in a task log and send a daily summary email to everyone with something 'assigned to' them, showing what is past due, due today, and coming due within two days.

Everything is being returned fine, but I need to get a user's email based on their ID.

Sample JSON returned (sanitized a bit):

  {
    "__metadata": {
      "id": "Web/Lists(guid'3e4fa151-ee48-46f9-8283-2c0e80145ab8')/Items(8)",
      "uri": "https://<server>/<custom site>/_api/Web/Lists(guid'GUIDHERE')/Items(8)",
      "etag": "\"12\"",
      "type": "SP.Data.Task_x0020_LogListItem"
    },
    "AssignedTo": {
      "results": [
        {
          "__metadata": {
            "id": "472ce0fc-6066-4bd9-9784-9d3f0fc2a264",
            "type": "SP.Data.UserInfoItem"
          },
          "FirstName": "First Name",
          "LastName": "Last Name"
        }
      ]
    },
    "Title": "Task Tile Here",
    "AssignedToId": {
      "__metadata": {
        "type": "Collection(Edm.Int32)"
      },
      "results": [
        7403
      ]
    },
    "DueDate": "2015-09-30T04:00:00Z",
    "Priority": "3"
  }

Specifically this part:

"AssignedToId": {
          "__metadata": {
            "type": "Collection(Edm.Int32)"
          },
          "results": [
            7403
          ]
        }

How can I look up profile information for user 7403?

I've tried the User Profile Web Service but nothing (to my current knowledge) allows a lookup by ID, it's find user profile by username, or email, etc.

Basically I just need to get the email address for the user the task is assigned to.

Also, as a bonus question, I can't seem to access FirstName and LastName in AssignedTo. I am using JSON.Net and I have deserialized the entire object that is returned, but should I be doing something differently with this "nested" JSON?

1

There is a REST function that is 'GetUserByID' From here: https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_User

function getUser(id){
var returnValue;
  jQuery.ajax({
   url: "http://YourSite/_api/Web/GetUserById(" + id + ")",
   type: "GET",
   headers: { "Accept": "application/json;odata=verbose" },
   success: function(data) {
           var dataResults = data.d;
      //get login name  
      var loginName  = dataResults.LoginName.split('|')[1];
      alert(loginName);     
      //get display name
      alert(dataResults.Title);
   }
 });
}

Excerpt from here

  • Superb. Not sure how I missed that in my googling. It is much appreciated! – Soulfire Jul 15 '15 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.