4.3 Insert a New List Item

SharePoint

The following example illustrates the exchange of messages required for a client to insert a new Employees list item to the Employees list and associate it with Projects list item 2 and 3 using the AtomPub format.

HTTP Request:

 POST /_vti_bin/ListData.svc/Employees HTTP/1.1
 Accept: application/atom+xml
 Content-Type: application/atom+xml
 Host: www.contoso.com
 Content-Length: ###
 Expect: 100-continue
  
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
   xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
   xmlns="http://www.w3.org/2005/Atom">
   <category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" 
     term="Microsoft.SharePoint.DataService.EmployeesItem" />
   <title />
   <author>
     <name />
   </author>
   <updated>2009-04-30T02:15:21.1353156Z</updated>
   <id />
   <link href="http://www.contoso.com/_vti_bin/ListData.svc/Projects(2)" 
     rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Projects" 
     type="application/atom+xml;type=feed" />
   <link href="http://www.contoso.com/_vti_bin/ListData.svc/Projects(3)" 
     rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Projects" 
     type="application/atom+xml;type=feed" />
   <content type="application/xml">
     <m:properties>
       <d:Created m:type="Edm.DateTime" m:null="true" />
       <d:FullName>James Earl Jones</d:FullName>
       <d:HireDate m:type="Edm.DateTime">1987-04-29T19:15:14.7861156-07:00</d:HireDate>
       <d:ID m:type="Edm.Int32">0</d:ID>
       <d:Modified m:type="Edm.DateTime" m:null="true" />
       <d:Path m:null="true" />
       <d:Salary m:type="Edm.Double">195000</d:Salary>
       <d:Version m:null="true" />
       <d:Owshiddenversion m:type="Edm.Int32" m:null="true" />
     </m:properties>
   </content>
 </entry>

HTTP Response:

 HTTP/1.1 201 Created
 Cache-Control: no-cache
 Content-Type: application/atom+xml;charset=utf-8
 ETag: W/"1"
 Location: http://www.contoso.com/_vti_bin/ListData.svc/Employees(11)
 Server: Microsoft-IIS/7.0
 SPRequestGuid: 49759c6a-7a76-44fc-bd4c-e6bfe3f97a3e
 DataServiceVersion: 2.0;
 X-AspNet-Version: 2.0.50727
 Set-Cookie: SDA_Callback=05/01/2009 14:07:39; expires=Fri, 01-May-2009 21:17:39 GMT; path=/
 Set-Cookie: WSS_KeepSessionAuthenticated={afbe7ca4-c701-4f7d-9021-25cab947ae3f}; path=/
 X-Powered-By: ASP.NET
 MicrosoftSharePointTeamServices: 14.0.0.4006
 Date: Fri, 01 May 2009 21:07:41 GMT
 Content-Length: ###
  
 <?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <entry xml:base="http://www.contoso.com/_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://www.contoso.com/_vti_bin/ListData.svc/Employees(11)</id>
   <title type="text">James Earl Jones</title>
   <updated>2009-05-01T21:07:41Z</updated>
   <author>
     <name />
   </author>
   <link rel="edit" title="EmployeesItem" href="Employees(11)" />
   <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Projects" 
     type="application/atom+xml;type=feed" title="Projects" 
     href="Employees(11)/Projects" />
   <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CreatedBy" 
     type="application/atom+xml;type=entry" title="CreatedBy" 
     href="Employees(11)/CreatedBy" />
   <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ModifiedBy" 
     type="application/atom+xml;type=entry" title="ModifiedBy" 
     href="Employees(11)/ModifiedBy" />
   <category term="Microsoft.SharePoint.DataService.EmployeesItem" 
     scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
   <content type="application/xml">
     <m:properties>
       <d:FullName>James Earl Jones</d:FullName>
       <d:Salary m:type="Edm.Double">195000</d:Salary>
       <d:HireDate m:type="Edm.DateTime">1987-04-29T19:15:14.7861156-07:00</d:HireDate>
       <d:ID m:type="Edm.Int32">11</d:ID>
       <d:Modified m:type="Edm.DateTime">2009-05-01T14:07:41</d:Modified>
       <d:Created m:type="Edm.DateTime">2009-05-01T14:07:41</d:Created>
       <d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
       <d:Version>1.0</d:Version>
       <d:Path>/Lists/Employees</d:Path>
     </m:properties>
   </content>
 </entry>
Show: