使用Microsoft Graph将图像发布到列表共享点中

时间:2019-05-15 14:38:47

标签: c# sharepoint microsoft-graph .net-core-2.1

我正在使用Microsoft Graph API开发MS Sharepoint。我用.Net Core v2.1调用MS Graph API。

我想对其中一个列是图像列的Sharepoint List进行POST请求,但是我找不到有关如何执行此操作的文档...请问有人知道如何执行此操作吗?

更新

我看到了这个post,并且更改了json:

{
  "fields": {
    "Title": "Test",
    "Photo": {
      "Url": "https://myurl/picture.jpg",
      "Description":"This is my picture"
    }
  }
}

但是我有此错误消息:

{
    "error": {
        "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
        "message": "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value.",
        "innerError": {
            "request-id": "34773f4f-131f-4249-8a03-b8a820ba4a6b",
            "date": "2019-05-16T13:26:17"
        }
    }
}

似乎期望照片的值是PrimitiveValue,而不是对象...

1 个答案:

答案 0 :(得分:0)

也许这应该对您有帮助。

  

开机自检   https://graph.microsoft.com/v1.0/sites/ {site-id} / lists / {list-id} / items

假设您的所有图像已经上传到您的站点资产文件夹中。为具有网站资产图片URL ID

的图片列添加了以下JSON
POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items
Content-Type: application/json

{
  "fields": {
    "Title": "Widget",
    "Color": "Purple",
    "Weight": 32,
    "image": "/assets/image5.png" 
  }
}

参考:https://docs.microsoft.com/en-us/graph/api/listitem-create?view=graph-rest-1.0&tabs=javascript

希望有帮助