Created
July 23, 2013 19:47
-
-
Save mikekunze/6065541 to your computer and use it in GitHub Desktop.
This is an example of how to post an item to a SharePoint 2013 list. You must have the list itemType and list contextinfo tokens available prior to adding items to SharePoint via REST API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = "domain\\username" | |
pass = "password" | |
url = "http://sharepoint/siteCollection" | |
list = "listName" | |
# These two variables need to be obtained from the sharepoint server | |
itemType = "SP.Data.SomethingListItem" | |
context = "some really long hex string value" | |
# Define the request fn | |
request = require 'request' | |
addListItemByTitle: (title, item, context, cb)-> | |
processRequest = (err, res, body)-> | |
cb(err, JSON.parse(body).d) | |
config = | |
headers : | |
"Accept": "application/json;odata=verbose" | |
"X-RequestDigest": context | |
"content-type": "application/json;odata=verbose" | |
url : "#{url}/_api/web/lists/getbytitle('#{title}')/items" | |
body: JSON.stringify(item) | |
request.post(config, processRequest).auth(user, pass, true) | |
# Run the request | |
item = | |
__metadata: | |
type: itemType | |
Title: "NodeGeneratedTest" + Math.random() | |
addListItemByTitle list, item, context, (err, res)-> | |
console.log err || res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment