简体   繁体   English

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

[英]SharePoint 2013 - Associating Site Columns With Content Types Using the REST API

I'm trying to use the REST API to programatically create site columns and content types. 我正在尝试使用REST API以编程方式创建网站栏和内容类型。 Everything works fine until I try to associate my site columns with my content types. 一切正常,直到我尝试将网站列与内容类型相关联。

By this point in my code the site columns and content types already exist... 至此,在我的代码中,网站列和内容类型已经存在...

I am sending a POST to the following URL... 我正在将POST发送到以下URL ...

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

Here is the information I am sending in the request body... 这是我在请求正文中发送的信息...

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

Here is the error I get back in response... 这是我得到回应的错误...

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

I have tried several other options without success. 我尝试了其他几种选择,但均未成功。 For example, I have tried using "__metadata" : { "type": "SP.FieldLinkCreationInformation"} but everything I try with this __metadata type result in this error... 例如,我尝试使用“ __metadata”:{“ type”:“ 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."}}}

It sounds like SharePoint is telling me that this "type" is invalid. 听起来SharePoint告诉我此“类型”无效。 It seems like this should be possible with SharePoint 2013 since the documentation seems to imply that its possible... SharePoint 2013似乎应该有这种可能,因为该文档似乎暗示它可能...

documentation 文件

If anyone has any ideas I would be greatful for the suggestions. 如果有人有任何想法,我将非常乐意为您提供建议。 Thanks! 谢谢!

Based on the documentation, I would try that: 根据文档,我会尝试:

Endpoint (note the /add at the end): 端点(注意最后的/add ):

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

Body (wrap your properties in a parameters property): 正文(将您的属性包装在parameters属性中):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM