通过一次 API 调用通过 Flow 创建文档库

Creating Document Libraries through Flow with a single API call

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

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

Error

错误消息挑出了 Headers,但我不确定问题出在哪里? 请参阅以下流程中的 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"
                    }
                }
            ]
        }
    }
}

有人能提供任何见解吗?

谢谢!

"Weird, works for me"

Header 参数和请求的 body 一样正确(不区分大小写)。 MS Flow 有时会完全无法解释。

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

为了令牌 JSON 解析目的,我使用了这个模式:

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