sharepoint rest api Add ListItem 报错
Recently, I was trying to create a list item using Rest API on Sharepoint 2013. I got the following error message
“error”:{
“code”:”-2130575251, Microsoft.SharePoint.SPException”,
“message”:{
“lang”:”en-US”,
“value”:”The security validation for this page is invalid and might be corrupted. Please use your web browser’s Back button to try your operation again.”
}
}
Solution:
I found the solution for the above issue, most likely this error occurs since form digest has been expired on the page. In that case you could acquire a new form digest value by making a POST request to /_api/contextinfo endpoint. I’ve implemented the helper method for retrieving form digest.
Example :
function getFormDigest(siteUrl) {
return $.ajax({
url: siteUrl + “/_api/contextinfo”,
method: “POST”,
headers: { “Accept”: “application/json; odata=verbose” }
});
}
function createListItem(siteUrl, listName, itemProperties) {
var itemType = getItemTypeForListName(listName);
itemProperties[“__metadata”] = { “type”: itemType };
return getFormDigest(siteUrl).then(function (data) {
return $.ajax({
url: siteUrl + “/_api/web/lists/getbytitle(‘” + listName + “‘)/items”,
type: “POST”,
processData: false,
contentType: “application/json;odata=verbose”,
data: JSON.stringify(itemProperties),
headers: {
“Accept”: “application/json;odata=verbose”,
“X-RequestDigest”: data.d.GetContextWebInformation.FormDigestValue
}
});
});
}
//Fetch metadata for list item
function getItemTypeForListName(name) {
return “SP.Data.” + name.charAt(0).toUpperCase() + name.split(” “).join(“”).slice(1) + “ListItem”;
}
//Create a list item
var itemProperties = {‘Title’: ‘Title 1’};
createListItem(_spPageContextInfo.webAbsoluteUrl, ‘Demo List’, itemProperties)
.done(function (data) {
console.log(‘Item has been added successfully’);
})
.fail(function (error) {
console.log(JSON.stringify(error));
});
Usage :
var itemProperties = {‘Title’: ‘Title 1’};
createListItem(_spPageContextInfo.webAbsoluteUrl, ‘Test List’, itemProperties);
sharepoint rest api Add ListItem 报错的更多相关文章
- SharePoint 2013 点击"关注" 报错
现象: 点击"关注" 报错. 解决办法: 1.确保bin文件夹下的.dll版本与web.config一致. 2.设置user porfile权限. 2.重启iis 结果如下:
- JAVA Api 调用Hbase报错锦集
1. 报错 java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/protobuf/generated/MasterProtos$Master ...
- 【git 问题小说说】 git add时候报错:LF will be replaced by CRLF
本文来自:http://blog.csdn.net/loovejava/article/details/22114477 最近工作在window平台,不怎么使用命令行了所以导致很多命令都不熟悉啦 哈哈 ...
- 关于add migration 报错的问题解决方案
The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.In ...
- O365(世纪互联)SharePoint 之使用Designer报错
前言 在SharePoint Online中使用Designer报错,错误为:This Feature has been disabled by your administrator.找了好久发现原因 ...
- DataTable经典报错{列/行已属于其他表}
Delete()之后需要datatable.AccepteChanges()方法确认完全删除,因为Delete()只是将相应列的状态标志为删除, 还可以通过datatable.RejectChange ...
- sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户
现象: sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户 处理办法: 1.Open the Exchange Management Shell 2.输入: New-Mana ...
- sharepoint 2013 文档库 资源管理器打开报错 在文件资源管理器中打开此位置时遇到问题,将此网站添加到受信任站点列表,然后重试。
我们在使用sharepoint 2013的文档库或者资源库的时候,经常会需要用到使用“资源管理器”来管理文档,但是有时候,点击“使用资源管理器打开”,会提示如下错误: 在文件资源管理器中打开此位置时遇 ...
- DataTables学习:从最基本的入门静态页面,使用ajax调用Json本地数据源实现前端开发深入学习,根据后台数据接口替换掉本地的json本地数据,以及报错的处理地方,8个例子(显示行附加信息,回调使用api,动态显示和隐藏列...),详细教程
一.DataTables 个人觉得学习一门新的插件或者技术时候,官方文档是最根本的,入门最快的地方,但是有时候看完官方文档,一步步的动手写例子,总会出现各种莫名其妙的错误,需要我们很好的进行研究出错 ...
随机推荐
- python中单下划线和双下滑线
使用单下划线(_one_underline)开头表示方法不是API的一部分,不要直接访问(虽然语法上访问也没有什么问题). 使用双下划线开头(__two_underlines)开头表示子类不能覆写该方 ...
- openlayers研究(一) 初始化流程
下载2.13.1.解压缩.根据readme解释,openlayers.js是一个压缩库,.light是一个图像显示的简化库,mobile顾名思义应该是应对移动设备的库.build里面有py写的打包工具 ...
- 在Oracle/SQL Service中通过Function返回Table
本函数用途:返回一个Table 在Oracle中实现,范例: --在Types中: create or replace type objTable as object ( s_usercode var ...
- vue3.0环境最新安装步骤
安装最新的node.js版本: https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi 安装vue: npm install -g @vue/cli ...
- MyBatis基本配置和实践(三)
一.输入映射和输出映射 mapper.xml映射文件中定义了操作数据库的sql,每条sql就是一个statement,映射文件是MyBatis的核心. 1.parameterType(输入类型) 简单 ...
- IIS7 使用server farms 进行负载均衡
1.首先,到微软官网下载web平台安装程序: https://www.microsoft.com/web/downloads/ 2.安装好后,会在IIS里有这个图标: 3.双击这个图标:安装 4.安装 ...
- Python 装饰器的总结
先来了解几个定义: 1,函数 在python中,函数通过def关键字.函数名和可选的参数列表定义.通过return关键字返回值.我们举例来说明如何定义和调用一个简单的函数: #coding:UTF8 ...
- String str = "1,2,3,4,5,6" 如何将这个字符串转换成int数组
String str = "1,2,3,4,5,6"; string[] strS = str.Split(','); int[] num = new int[strS.Lengt ...
- 如何写自定义的AlertView
如何写自定义的AlertView 效果 说明 考虑到后面的可定制性以及可维护性,本人用AbstractAlertView定义了AlertView抽象的基类,实现通过子类来完成. 注:这只是粗略的写了一 ...
- JavaScript学习---JavaScript深入学习
对象的概念 对象分类[3种]: ECMScript(JS自己的对象), BOM(浏览器对象) DOM(文档对象,操作HTML的) 11种内置对象: Array ,String ...