0

In an azure logic app I would like to save images which are given as a url in a json string. They should be saved in a sharepoint folder. The json string is very long but shortened looks somewhat like this:

{"id":"123","Person":{"Name":"Testmann","Firstname":"Tim"},"Timestamp":"2023-03-22T20:16:04.663252+01:00","Tree":{"fileId":"123","fileName":"Tree_2023_03_22_19_16_09.png","timestamp":"2023-03-22T19:16:09.082243Z","contentType":"image/png","size":123,"url":"https://path"}}

In this example the person Tim Testmann took the picture of a certain tree at a certain time. The string can contain several images, for example of the root of the tree, one doesn't know how many images will come in advance.

Does anyone know how to save the images in sharepoint? One probably has to extract all the images from the string first.

Thanks a lot for any help! Any help highly appreciated.

Edit:

The actual json looks more like the version below. There is general info as well as several images in the same json type. How can I extract just the images and save each one in sharepoint? Thanks again!

{"id":"123","Person":{"Name":"Testmann","Firstname":"Tim"},"Timestamp":"2023-03-22T20:16:04.663252+01:00","Tree1":{"fileId":"123","fileName":"Tree_2023_03_22_19_16_09.png","timestamp":"2023-03-22T19:16:09.082243Z","contentType":"image/png","size":63865,"url":"https://path"},"Tree2":{"fileId":"1234","fileName":"Tree2_2023_03_22_19_16_09.png","timestamp":"2023-03-22T19:16:09.082243Z","contentType":"image/png","size":63865,"url":"https://path2","Tree3":{"fileId":"12345","fileName":"Tree3_2023_03_22_19_16_09.png","timestamp":"2023-03-22T19:16:09.082243Z","contentType":"image/png","size":63865,"url":"https://path3"}}

Anna
  • 81
  • 5

1 Answers1

1

After reproducing from my end, I could able to achieve your requirement following the below steps.

For demonstration purposes, I have used the below Json taking sample image url.

{
  "id": "123",
  "Person": {
    "Name": "Testmann",
    "Firstname": "Tim"
  },
  "Timestamp": "2023-03-22T20:16:04.663252+01:00",
  "Tree": {
    "fileId": "123",
    "fileName": "Tree_2023_03_22_19_16_09.png",
    "timestamp": "2023-03-22T19:16:09.082243Z",
    "contentType": "image/png",
    "size": 123,
    "url": "https://www.thewowstyle.com/wp-content/uploads/2015/02/now-i-am-free.jpg"
  }
}

Below is the complete flow of my logic apps

enter image description here

Below is the parse json action schema of my logic app

{
    "type": "object",
    "properties": {
        "id": {
            "type": "string"
        },
        "Person": {
            "type": "object",
            "properties": {
                "Name": {
                    "type": "string"
                },
                "Firstname": {
                    "type": "string"
                }
            }
        },
        "Timestamp": {
            "type": "string"
        },
        "Tree": {
            "type": "object",
            "properties": {
                "fileId": {
                    "type": "string"
                },
                "fileName": {
                    "type": "string"
                },
                "timestamp": {
                    "type": "string"
                },
                "contentType": {
                    "type": "string"
                },
                "size": {
                    "type": "integer"
                },
                "url": {
                    "type": "string"
                }
            }
        }
    }
}

Results:

enter image description here

enter image description here

Update


This can be done using Json Properties to Name Value Pair Array action. Below is something that you can do to achieve your requirement.

enter image description here

Flow inside True block

enter image description here

Results:

enter image description here

enter image description here

Code-view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Compose_2": {
                        "inputs": "@items('For_each')",
                        "runAfter": {},
                        "type": "Compose"
                    },
                    "Condition": {
                        "actions": {
                            "Create_file": {
                                "inputs": {
                                    "body": "@body('HTTP')",
                                    "host": {
                                        "connection": {
                                            "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                                        }
                                    },
                                    "method": "post",
                                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://<>.sharepoint.com/<>/<>'))}/files",
                                    "queries": {
                                        "folderPath": "/Shared Documents/urlImages",
                                        "name": "@{items('For_each')['propertyValue'][1]['propertyValue']}",
                                        "queryParametersSingleEncoded": true
                                    }
                                },
                                "runAfter": {
                                    "HTTP": [
                                        "Succeeded"
                                    ]
                                },
                                "runtimeConfiguration": {
                                    "contentTransfer": {
                                        "transferMode": "Chunked"
                                    }
                                },
                                "type": "ApiConnection"
                            },
                            "HTTP": {
                                "inputs": {
                                    "method": "GET",
                                    "uri": "@{items('For_each')['propertyValue'][5]['propertyValue']}"
                                },
                                "runAfter": {},
                                "type": "Http"
                            }
                        },
                        "expression": {
                            "and": [
                                {
                                    "not": {
                                        "equals": [
                                            "@items('For_each')['propertyName']",
                                            "id"
                                        ]
                                    }
                                },
                                {
                                    "not": {
                                        "equals": [
                                            "@items('For_each')['propertyName']",
                                            "Person"
                                        ]
                                    }
                                },
                                {
                                    "not": {
                                        "equals": [
                                            "@items('For_each')['propertyName']",
                                            "Timestamp"
                                        ]
                                    }
                                }
                            ]
                        },
                        "runAfter": {
                            "Compose_2": [
                                "Succeeded"
                            ]
                        },
                        "type": "If"
                    }
                },
                "foreach": "@body('Json_Properties_to_Name_Value_Pair_Array')",
                "runAfter": {
                    "Json_Properties_to_Name_Value_Pair_Array": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Json_Properties_to_Name_Value_Pair_Array": {
                "inputs": {
                    "body": {
                        "data": "@json(triggerBody())"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['advanceddataoperatio_1']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/JsonPropertiesToNameValuePairArray"
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "advanceddataoperatio_1": {
                    "connectionId": "/subscriptions/<subid>/resourceGroups/<rg>/providers/Microsoft.Web/connections/advanceddataoperatio-1",
                    "connectionName": "advanceddataoperatio-1",
                    "id": "/subscriptions/<subid>/providers/Microsoft.Web/locations/eastus/managedApis/advanceddataoperatio"
                },
                "sharepointonline": {
                    "connectionId": "/subscriptions/<subid>/resourceGroups/<rg>/providers/Microsoft.Web/connections/sharepointonline",
                    "connectionName": "sharepointonline",
                    "id": "/subscriptions/<subid>/providers/Microsoft.Web/locations/eastus/managedApis/sharepointonline"
                }
            }
        }
    }
}
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
  • Thanks so much for your help! Because of your images, it was really easy to follow and I was able to reproduce. This part works now! Now I've edited my question, as the next difficulty is to save images of several trees. I was thinking one has to extract all the tree objects first out of the entire json and then iterate over them with a for each statement. But I'm not sure exactly how to extract all the trees. Would you know? Thanks again! – Anna May 04 '23 at 08:57
  • @Anna, I have updated my answer for the updated requirements. Consider giving it a try. – SwethaKandikonda May 04 '23 at 12:10
  • Thanks again for your reply! I appreciate it a lot! Unfortunately I can't quite follow this this time. I'm confused as we aren't parsing anymore. Within the condition box I can't select the propertyname and the id, Person and Timestamp. Could you maybe expand your 'JSON properties to value name array' box? Thanks you! – Anna May 04 '23 at 13:14
  • @Anna, You can refer this image for better understanding. https://i.imgur.com/f3YzIWq.png. However, I have added my whole logic app code view, do consider checking that if you get stuck at any point. – SwethaKandikonda May 05 '23 at 01:03