Managing Lists with the MashPoint REST API

In my previous post I showed you how to create and delete Webs using the REST API. In this post I will show you how to create delete and update Lists. Hopefully you will see how similar it is to managing Webs.

To create a List you will have to POST to the Lists collection of a Web. So let's browse to our subweb that we created in the previous post. You can download MashPoint REST API for SharePoint here
webs
 
Lists
Click the Lists link to get to the Lists collection.
ListsCollection

Now to create a new Lists we should POST to this collection. My URI looks like this: http://jndtvbx64/mashpoint/1/Webs/7ca3778b-12de-471d-b53f-afe6be2c815e/Lists

Below is a code snippet that will create a new Document Library named MyDocLib.
void CreateDocumentLibrary()
{
    string uri = "http://jndtvbx64/mashpoint/1/Webs/7ca3778b-12de-471d-b53f-afe6be2c815e/Lists";
    string title = "MyDocLib";
    string templateType = Microsoft.SharePoint.SPListTemplateType.DocumentLibrary.ToString();

    WebClient wc = new WebClient();
    wc.Credentials = CredentialCache.DefaultCredentials;
    NameValueCollection values = new NameValueCollection();
    values["Title"] = title;
    values["Description"] = "A list created from REST";
    values["TemplateType"] = templateType;
    values["AllowEveryoneViewItems"] = true.ToString();
    values["EnableMinorVersions"] = true.ToString();

    wc.UploadValues(uri, "POST", values);

    string newuri = wc.ResponseHeaders.Get("Location");
    Console.WriteLine(newuri);
}
 
Here is the corresponding HTML form.
<?xml version="1.0" encoding="utf-8" ?>
<html>
  <body>
    <form 
method="POST" 
action="http://jndtvbx64/mashpoint/1/Webs/7ca3778b-12de-471d-b53f-afe6be2c815e/Lists" >

      <input type="text" name="Title" value="MyDocLib" />
      <input type="text" name="Description" value="A list created from REST" />
      <input type="text" name="TemplateType" value="DocumentLibrary"/>
      <input type="text" name="AllowEveryoneViewItems" value="true"/>
      <input type="text" name="EnableMinorVersions" value="true"/>
      <input type="submit" name="Create" value="Create"/>
    </form>
  </body>
</html>
Here is the created list.
MyDocLib
MyDocLibDetail


To update a List we need to send a PUT request to the URI of the list sending the updated properties.
The code below will update the list we just created. The form fields corresponds to the Properties of the SPList object.
void UpdateDocumentLibrary()
{
    string uri = 
"http://jndtvbx64/mashpoint/1/Webs/7ca3778b-12de-471d-b53f-afe6be2c815e/Lists/MyDocLib";
    string title = "UpdatedTitle";
    string templateType = Microsoft.SharePoint.SPListTemplateType.DocumentLibrary.ToString();

    WebClient wc = new WebClient();
    wc.Credentials = CredentialCache.DefaultCredentials;
    NameValueCollection values = new NameValueCollection();
    values["Title"] = title;
    values["Description"] = "Updated Desription";
    values["AllowEveryoneViewItems"] = false.ToString();
    values["EnableMinorVersions"] = false.ToString();
    values["EnableSyndication"] = true.ToString();
    values["OnQuickLaunch"] = true.ToString();

    wc.UploadValues(uri, "PUT", values);
}
To delete a list we need to send a DELETE request to the list URI. 
void DeleteDocumentLibrary()
{
    string uri = 
"http://jndtvbx64/mashpoint/1/Webs/7ca3778b-12de-471d-b53f-afe6be2c815e/Lists/MyDocLib";
    
    WebClient wc = new WebClient();
    wc.Credentials = CredentialCache.DefaultCredentials;
    NameValueCollection values = new NameValueCollection();
    
    wc.UploadValues(uri, "DELETE", values);
}
I will issue the DELETE from Fiddler.
Fiddler.Delete

In the next post I will show how to manage Fields with the MashPoint REST API.

Posted Aug 13 2009, 11:00 AM by Jonas Nilsson

Blogs

    MashPoint - A Breakthrough in SharePoint Data Integration
  • Home

Bamboo Nation, Media Sponsor of:

SPTechCon

Download MashPoint Now!

MashPoint - Data Integration for SharePointDownload the official MashPoint release, available as of November 7th, 2008.

Jonas Nilsson Q&A

Bamboo Nation Almost Everywhere

Follow Bamboo Nation on:Bamboo Solutions on Facebook

Bamboo Solutions on Google+

Bamboo Solutions on LinkedIn

Bamboo Solutions on Twitter

Bamboo Solutions on YouTube

SharePoint Calendars

SharePoint Calendars

Bamboo Solutions Corporation, 2002-2012