sharepointazure-logic-appscreatefile

from azure logic app how to set title of a file in sharepoint that was created in flow


I would like to create a file with a title in SharePoint using an Azure Logic App. However, the 'create file' action for SharePoint does not provide a field to set the file title (and there is no option to add a new parameter, as seen in pic 1 below).

enter image description here

Upon researching, I discovered that the 'update file properties' action allows entry of a file title. However, this operation requires the file ID (as seen in pic 2 below), which SharePoint creates and I don't have.

enter image description here

I asked chatgbt for help, and they suggested getting the file properties, then searching for the file ID. However, this approach generates the error "column Name doesn't exist" for the query Name eq test.png. All workarounds suggested by chatgbt appear to be increasingly complicated and are not working.

enter image description here

How can I set the file title for a file I just created in my flow in SharePoint? Thank you in advance!


Solution

  • this operation requires the file ID (as seen in pic 2 below), which SharePoint creates and I don't have.

    I have reproduced in my environment and got expected results as below:

    Design:

    enter image description here

    You will get id previous steps as i have got.

    Code view:

    
    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Create_file": {
                    "inputs": {
                        "body": "@triggerBody()",
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                            }
                        },
                        "method": "post",
                        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://microsoftapc.sharepoint.com/teams/StackOverflowSupport'))}/files",
                        "queries": {
                            "folderPath": "/Shared Documents/TEST1",
                            "name": "EmoRA",
                            "queryParametersSingleEncoded": true
                        }
                    },
                    "runAfter": {},
                    "runtimeConfiguration": {
                        "contentTransfer": {
                            "transferMode": "Chunked"
                        }
                    },
                    "type": "ApiConnection"
                },
                "Update_file_properties": {
                    "inputs": {
                        "body": {
                            "Title": "Testing Rithwik"
                        },
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                            }
                        },
                        "method": "patch",
                        "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://microsoftapc.sharepoint.com/teams/StackOverflowSupport'))}/tables/@{encodeURIComponent(encodeURIComponent('428d88e4-22a3-4ab1-9cc7-0abd79c95be9'))}/items/@{encodeURIComponent(body('Create_file')?['ItemId'])}/patchfileitem"
                    },
                    "runAfter": {
                        "Create_file": [
                            "Succeeded"
                        ]
                    },
                    "type": "ApiConnection"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {}
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "sharepointonline": {
                        "connectionId": "/subscriptions/b83c/resourceGroups/bojja/providers/Microsoft.Web/connections/sharepointonline",
                        "connectionName": "sharepointonline",
                        "id": "/subscriptions/b83/providers/Microsoft.Web/locations/eastus/managedApis/sharepointonline"
                    }
                }
            }
        }
    }
    

    Output:

    enter image description here

    enter image description here

    So after creating a file you get ItemId which can be used to updating the files title as I have done.