locked
REST API - How to get author name RRS feed

  • Question

  • The SharePoint 2010 REST API is pretty awesome, but I'm at a loss for how to get friendly name of the user who authored a given list item.  The default query returns a CreatedByID field and a ModifiedByID field, which are numeric IDs, but I don't know how to translate these into the friendly name without performing a whole bunch of additional queries on the user information list. 

    The ATOM feed also includes an <author><name/><author> node, but this is consistently blank.

    Anybody know how to get the author's name?

    Thanks!

    Friday, August 6, 2010 3:24 PM

Answers

  • This works for me.

    http://myserver/_vti_bin/listdata.svc/Announcements(1)/CreatedBy

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <entry xml:base="http://spf2010/_vti_bin/listdata.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/&quot;1&quot;" xmlns="http://www.w3.org/2005/Atom">
      <id>http://spf2010/_vti_bin/listdata.svc/UserInformationList(1073741823)</id>
      <title type="text">System Account</title>
      <updated>2010-08-11T14:14:05-04:00</updated>
      <author>
        <name />
      </author>
      <link rel="edit" title="UserInformationListItem" href="UserInformationList(1073741823)" />
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CreatedBy" type="application/atom+xml;type=entry" title="CreatedBy" href="UserInformationList(1073741823)/CreatedBy" />
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ModifiedBy" type="application/atom+xml;type=entry" title="ModifiedBy" href="UserInformationList(1073741823)/ModifiedBy" />
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attachments" type="application/atom+xml;type=feed" title="Attachments" href="UserInformationList(1073741823)/Attachments" />
      <category term="Microsoft.SharePoint.DataService.UserInformationListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
      <content type="application/xml">
        <m:properties>
          <d:Id m:type="Edm.Int32">1073741823</d:Id>
          <d:ContentTypeID>0x010A006D194B3E7071F74E877C48AEAB1DD3AC</d:ContentTypeID>
          <d:ContentType>Person</d:ContentType>
          <d:Name>System Account</d:Name>
          <d:Modified m:type="Edm.DateTime">2010-08-11T14:14:05</d:Modified>
          <d:Created m:type="Edm.DateTime">2010-08-11T14:14:05</d:Created>
          <d:CreatedById m:type="Edm.Int32">1</d:CreatedById>
          <d:ModifiedById m:type="Edm.Int32">1</d:ModifiedById>
          <d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
          <d:Version>1.0</d:Version>
          <d:Path>/_catalogs/users</d:Path>
          <d:Account>SHAREPOINT\system</d:Account>
          <d:EMail m:null="true" />
          <d:MobileNumber m:null="true" />
          <d:AboutMe m:null="true" />
          <d:SIPAddress m:null="true" />
          <d:IsSiteAdmin m:type="Edm.Boolean">false</d:IsSiteAdmin>
          <d:Deleted m:type="Edm.Boolean">false</d:Deleted>
          <d:Picture m:null="true" />
          <d:Department m:null="true" />
          <d:JobTitle m:null="true" />
        </m:properties>
      </content>
    </entry>

     

    • Proposed as answer by Doug WareMVP Thursday, August 12, 2010 2:43 PM
    • Marked as answer by Philip Lanier Thursday, August 12, 2010 4:54 PM
    Wednesday, August 11, 2010 7:42 PM
  • Awesome Doug, thanks!  Almost what I needed, but gets me to where I need to go.  Since I need to display all list items with the author, I can simply use inline expansion on the CreatedBy property as follows:

    http://myserver/_vti_bin/listdata.svc/Announcements?$expand=CreatedBy

    Also, had I realized it, the "<link>" tags (see Doug's response) provide some clues as to properties/relationships that can be expanded. 

    Finally, it's worth noting that this property is not available in SP2010 Beta 2, for those of you who still have a rogue/legacy dev machine.  :-)

    • Marked as answer by Philip Lanier Thursday, August 12, 2010 4:54 PM
    Thursday, August 12, 2010 4:54 PM

All replies

  • Hi, Philip Lanier

     

           Did you use Web-service to retrieve the list data via web-service?

           Would you please kindly let me know which web-method you used?

           Thanks for your understanding!

          

    Best Regards,

    Aaron

    Monday, August 9, 2010 7:45 AM
  • Hi Aaron,

    Sorry if I was unclear. I'm using the REST API, not web services.  See http://msdn.microsoft.com/en-us/library/ff521587.aspx

    The GET request I'm making is essentially http://myserver/subsite/_vti_bin/lists.svc/MyList

    Thanks,
    Phil

     

     

    Monday, August 9, 2010 6:52 PM
  • Based on the crickets, it sounds like there may not be a way to get the the author of an item directly via a REST call?

    Wednesday, August 11, 2010 7:26 PM
  • This works for me.

    http://myserver/_vti_bin/listdata.svc/Announcements(1)/CreatedBy

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <entry xml:base="http://spf2010/_vti_bin/listdata.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/&quot;1&quot;" xmlns="http://www.w3.org/2005/Atom">
      <id>http://spf2010/_vti_bin/listdata.svc/UserInformationList(1073741823)</id>
      <title type="text">System Account</title>
      <updated>2010-08-11T14:14:05-04:00</updated>
      <author>
        <name />
      </author>
      <link rel="edit" title="UserInformationListItem" href="UserInformationList(1073741823)" />
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CreatedBy" type="application/atom+xml;type=entry" title="CreatedBy" href="UserInformationList(1073741823)/CreatedBy" />
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ModifiedBy" type="application/atom+xml;type=entry" title="ModifiedBy" href="UserInformationList(1073741823)/ModifiedBy" />
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attachments" type="application/atom+xml;type=feed" title="Attachments" href="UserInformationList(1073741823)/Attachments" />
      <category term="Microsoft.SharePoint.DataService.UserInformationListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
      <content type="application/xml">
        <m:properties>
          <d:Id m:type="Edm.Int32">1073741823</d:Id>
          <d:ContentTypeID>0x010A006D194B3E7071F74E877C48AEAB1DD3AC</d:ContentTypeID>
          <d:ContentType>Person</d:ContentType>
          <d:Name>System Account</d:Name>
          <d:Modified m:type="Edm.DateTime">2010-08-11T14:14:05</d:Modified>
          <d:Created m:type="Edm.DateTime">2010-08-11T14:14:05</d:Created>
          <d:CreatedById m:type="Edm.Int32">1</d:CreatedById>
          <d:ModifiedById m:type="Edm.Int32">1</d:ModifiedById>
          <d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
          <d:Version>1.0</d:Version>
          <d:Path>/_catalogs/users</d:Path>
          <d:Account>SHAREPOINT\system</d:Account>
          <d:EMail m:null="true" />
          <d:MobileNumber m:null="true" />
          <d:AboutMe m:null="true" />
          <d:SIPAddress m:null="true" />
          <d:IsSiteAdmin m:type="Edm.Boolean">false</d:IsSiteAdmin>
          <d:Deleted m:type="Edm.Boolean">false</d:Deleted>
          <d:Picture m:null="true" />
          <d:Department m:null="true" />
          <d:JobTitle m:null="true" />
        </m:properties>
      </content>
    </entry>

     

    • Proposed as answer by Doug WareMVP Thursday, August 12, 2010 2:43 PM
    • Marked as answer by Philip Lanier Thursday, August 12, 2010 4:54 PM
    Wednesday, August 11, 2010 7:42 PM
  • Awesome Doug, thanks!  Almost what I needed, but gets me to where I need to go.  Since I need to display all list items with the author, I can simply use inline expansion on the CreatedBy property as follows:

    http://myserver/_vti_bin/listdata.svc/Announcements?$expand=CreatedBy

    Also, had I realized it, the "<link>" tags (see Doug's response) provide some clues as to properties/relationships that can be expanded. 

    Finally, it's worth noting that this property is not available in SP2010 Beta 2, for those of you who still have a rogue/legacy dev machine.  :-)

    • Marked as answer by Philip Lanier Thursday, August 12, 2010 4:54 PM
    Thursday, August 12, 2010 4:54 PM