SharePoint 2013 - 使用REST API将站点列与内容类型相关联

时间:2014-04-05 00:18:21

标签: rest sharepoint sharepoint-2013

我尝试使用REST API以编程方式创建网站列和内容类型。一切正常,直到我尝试将我的网站列与我的内容类型相关联。

到目前为止,在我的代码中,网站列和内容类型已经存在......

我正在向以下网址发送POST ...

http://mydevmachine/sites/claimsreports/_api/web/ContentTypes('0x01003E9D5AD94A5DCD46876B7BFFCEA9B60C')/FieldLinks

以下是我在请求正文中发送的信息......

{
  "__metadata": {
    "type": "SP.FieldLink"
  },
  "Id": "9400d057-ba2c-4ab4-9ce0-671b858fd849",
  "Name": "BusinessCategory",
  "Hidden": false,
  "Required": false
}

以下是我回复的错误......

{"error":{"code":"-2147467261, System.ArgumentNullException","message":{"lang":"en-US","value":"Value cannot be null.\r\nParameter name: parameters"}}}

我尝试了其他几个选项却没有成功。例如,我尝试过使用" __ metadata" :{"输入":" SP.FieldLinkCreationInformation"}但我尝试使用此__metadata类型的所有内容都会导致此错误...

{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A type named 'SP.FieldLinkCreationInformation' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."}}}

听起来像SharePoint告诉我这个"类型"是无效的。看起来这应该可以使用SharePoint 2013,因为文档似乎暗示它可能......

documentation

如果有人有任何想法,我会对这些建议感到满意。谢谢!

1 个答案:

答案 0 :(得分:0)

根据文档,我会尝试:

端点(注意最后的/add):

http://mydevmachine/sites/claimsreports/_api/web/ContentTypes('0x01003E9D5AD94A5DCD46876B7BFFCEA9B60C')/FieldLinks/add

Body(将您的属性包装在parameters属性中):

{"parameters":
{
"__metadata": {"type": "SP.FieldLink"},
"Id": "9400d057-ba2c-4ab4-9ce0-671b858fd849",
"Name": "BusinessCategory",
"Hidden": false,
"Required": false
}
}
相关问题