Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created April 4, 2015 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/905b37a0c5676f6152a8 to your computer and use it in GitHub Desktop.
Save vgrem/905b37a0c5676f6152a8 to your computer and use it in GitHub Desktop.
Example: create a List Item
using (var client = new SPHttpClient(webUri, userName, password))
{
var listTitle = "Tasks";
var itemPayload = new { __metadata = new { type = "SP.Data.TasksListItem" }, Title = "Approval Task"};
var endpointUrl = string.Format("{0}/_api/web/lists/getbytitle('{1}')/items",webUri,listTitle);
var data = client.ExecuteJson(endpointUrl,HttpMethod.Post,itemPayload);
Console.WriteLine("Task item '{0}' has been created",data["Title"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment