我正在尝试使用 JAVA Apache HTTP 客户端通过 rest API 更新 Share Point 库文档的元数据。
我能够从 SharePoint API 上下文中获取表单摘要值。但是在提交更新元数据的发布请求时收到错误 500(Microsoft.SharePoint.SPException)。
“错误代码:-2146232832,指定的对象不属于列表。”
您能否查看以下代码片段并建议我如何解决此问题?请注意,“ABC%20API%20POC”是 Sharepoint 库 (ABC API POC)。
HttpPost post = new HttpPost("/_api/contextinfo");
post.setHeader("Accept", "application/json; odata=verbose");
post.setHeader("content-type", "application/json; odata=verbose");
CloseableHttpResponse responseDigest = httpclient.execute(target, post,context);
byte[] content = EntityUtils.toByteArray(responseDigest.getEntity());
String jsonString = new String(content, "UTF-8");
JSONObject json = new JSONObject(jsonString);
String formDigestValue = json.getJSONObject("d").getJSONObject("GetContextWebInformation").getString("FormDigestValue");
//post request to update the metadata
String updateJson = "{'__metadata': { 'type': 'SP.ListItem'}, 'TestColumn':'TestingValue'}";
String filename="/DocumentRepository/ABC%20API%20POC/upload2.txt";
// ABC%20API%20POC- is a library
HttpPost updateMetaDateRequest = new HttpPost("/_api/web/GetFileByServerRelativeUrl('"+ filename + "')/ListItemAllFields");
updateMetaDateRequest.setHeader("X-RequestDigest", formDigestValue);
updateMetaDateRequest.setHeader("X-HTTP-Method", "MERGE");
updateMetaDateRequest.setHeader("If-Match", "*");
updateMetaDateRequest.setHeader("Accept", "application/json; odata=verbose");
updateMetaDateRequest.setHeader("content-type", "application/json; odata=verbose");
updateMetaDateRequest.setEntity(new StringEntity(updateJson));
try {
CloseableHttpResponse updateMetaDateResponse = httpclient.execute(target,updateMetaDateRequest,context);
int rc = updateMetaDateResponse.getStatusLine().getStatusCode();
String reason = updateMetaDateResponse.getStatusLine().getReasonPhrase();
if (rc != 200) {
System.out.println("updateMetaDateResponse" + " failed " +reason +rc );
}
else {
System.out.println("updateMetaDateResponse:" + rc + reason);
}
}
finally {
// if (updateMetaDateResponse != null) updateMetaDateResponse.close();
}