'Creating Document Libraries through Flow with a single API call

My company currently have client SharePoint sites hosted on our O365 tenant, and previously whenever a new client was bought on board we'd create a SharePoint site for them using the GUI or Powershell, but in the interest of making things a little easier in the long run I'm now in the process of trying to automate site creation for any new clients that join us - Historically, all sites have been designed the same with more or less the same structure, the only difference being the files themselves. I've managed to automate the bulk of the SharePoint site creation through flow (Creating the site, Hub site linkage, ownership of site, group membership, external access, etc.) but I'm having trouble with creating the document libraries on newly created sites. There are 8 libraries overall, and whilst I have actually worked out how to create them each individually using the 'Send a HTTP request to SharePoint" action (I'm quite new to Flow and all this!), I'd like to try and use MS Graph and JSON batching instead, so I can create all 8 libraries in a single API call.

I've tested my JSON on the MS Graph Explorer, which works and and creates the libraries on a specified client site as expected, but when I try and do it through Flow, I get the below error and I'm not sure where I'm going wrong:

Error

The error message singles out the Headers, but I'm not sure what the issue is? See below the HTTP action in the Flow:

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"
                    }
                }
            ]
        }
    }
}

Would anyone be able to offer any insight?

Thank you!



Solution 1:[1]

"Weird, works for me"

Header parameters are correct (case insensitive) as well as request's body. MS Flow sometimes behave totally unexplainably.

Please try again creating temporary flow with OAuth2 token HTTP request and Graph API HTTP request only.

For token JSON parsing purposes I used this schema:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nervuzz