【问题标题】:Creating Document Libraries through Flow with a single API call使用单个 API 调用通过 Flow 创建文档库
【发布时间】:2019-11-01 22:29:56
【问题描述】:

我的公司目前在我们的 O365 租户上托管了客户端 SharePoint 网站,以前每当在船上购买新客户端时,我们都会使用 GUI 或 Powershell 为他们创建一个 SharePoint 网站,但为了让事情变得更简单从长远来看更容易我现在正在尝试为任何加入我们的新客户自动创建网站 - 从历史上看,所有网站的设计都相同,结构或多或少相同,唯一的区别是文件本身.我已经设法通过流程(创建网站、中心网站链接、网站所有权、组成员资格、外部访问等)自动化了大部分 SharePoint 网站创建,但我在新创建文档库时遇到了问题创建的网站。总共有 8 个库,虽然我实际上已经弄清楚了如何使用“向 SharePoint 发送 HTTP 请求”操作单独创建它们(我对 Flow 和所有这些都很陌生!),我想尝试并改用 MS Graph 和 JSON 批处理,因此我可以在一个 API 调用中创建所有 8 个库。

我已经在 MS Graph Explorer 上测试了我的 JSON,它可以正常工作并按预期在指定的客户端站点上创建库,但是当我尝试通过 Flow 执行此操作时,我收到以下错误,但我没有确定我哪里错了:

Error

错误消息单独列出了标题,但我不确定问题是什么? 请参阅下面的流中的 HTTP 操作:

HTTP Action

{
"inputs": {
    "method": "POST",
    "uri": "https://graph.microsoft.com/v1.0/$batch",
    "headers": {
        "content-type": "application/json;odata=verbose",
        "authorization": "@{body('Parse_JSON')?['token_type']} @{body('Parse_JSON')?['access_token']}"
    },
    "body": {
        "requests": [
            {
                "id": "1",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Management",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "2",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Employees",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "3",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Work Activities",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "4",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Work Equipment",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "5",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Substances",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "6",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Workplaces",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "7",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "HR",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            },
            {
                "id": "8",
                "method": "POST",
                "url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
                "body": {
                    "displayName": "Quality",
                    "list": {
                        "template": "documentLibrary"
                    }
                },
                "headers": {
                    "content-type": "application/json"
                }
            }
        ]
    }
}

}

谁能提供任何见解?

谢谢!

【问题讨论】:

  • 您能否更新您的问题并从 Peek code 选项添加 HTTP 操作的完整 JSON 表示?
  • 嗨 - 查看更新的问题!

标签: json sharepoint microsoft-graph-api flow power-automate


【解决方案1】:

“奇怪,为我工作”

标头参数正确(不区分大小写)以及请求的正文。 MS Flow 有时表现得完全无法解释。

请再次尝试使用 OAuth2 令牌 HTTP 请求和 Graph API HTTP 请求创建临时流。

出于令牌 JSON 解析的目的,我使用了这个架构:

{
"type": "object",
"properties": {
    "token_type": {
        "type": "string"
    },
    "expires_in": {
        "type": "integer"
    },
    "ext_expires_in": {
        "type": "integer"
    },
    "access_token": {
        "type": "string"
    }
}
}

【讨论】:

  • 这实际上就是我的令牌模式的显示方式。无论如何,我刚刚创建了一个只有令牌请求和 API HTTP 请求的新流程,它工作了?!?我看不出问题出在哪里,因为它的编写方式与原始流程中的完全相同,所以我只好按照你所说的去做,只是流程表现得很奇怪。感谢您的帮助!
  • 还有一个很棒的 Microsoft Flow 教程,您可以看看。 docs.microsoft.com/en-us/graph/tutorials/flow
  • @Guero 不幸的是,无论 MS Flow 实际上多么伟大和有用,我不得不说它仍然是一个错误,有时唯一的解释是“没有解释”。回到你的问题 - 我认为使用Apply to each action + 例如。与使用单独的请求和调用 MS Graph API 的 $batch 端点对 JSON 进行硬编码相比,SharePoint 列表的分辨率可能更好(就透明度而言)
猜你喜欢
  • 1970-01-01
  • 2014-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多