2

I'm working on an Azure Logic App which is triggered everytime a JSON-file is added to a BLOB-storage. The JSON-file contains a CustomerId and based on this Id I want to sent the contents of the JSON-file to a different endpoint using an HTTP-request.

My Azure Logic App currently looks like this; enter image description here

I've been researching and trying a lot of things for the entire morning, but I can't get my head around this. I've tried things like;

json(body('Get_blob_content_using_path'))

and

decodeBase64(body('Get_blob_content_using_path'))

and just the default option like visible in the screenshot. But I can't figure out how to do this. All I want is go left or right based on the CustomerId.

So for clarity. The problem lies within the condition-step of the Logic App. I can retrieve the BLOB-file from the storage, but the issue is with parsing the CustomerId from the JSON so I can validate it within the condition. Does anybody has an idea on how I can fix this?

2
  • 1
    For clarity, is the problem retrieving the content or getting a value from the content you've successfully retrieved? Commented Apr 10, 2019 at 13:04
  • @Johns-305 Good question! I'll update the topic, hopefully that give some more clarity. The issue is within parsing the JSON inside the condition so I can check it. That's after retrieving the content. Commented Apr 10, 2019 at 13:12

1 Answer 1

5

In the end I was able to solve the issue by adding a compose step before the condition and after the steps which will get me the content of the BLOB-file. The compose get's the content of the blob-file which I then can validate against the CustomerId I want. This topic got me in the right direction for my solution.

UPDATE:

The final logic app looks like this; enter image description here

Which is begin created with the following logic app code;

{
    "$connections": {
        "value": {
            "azureblob": {
                "connectionId": "<snip>",
                "connectionName": "azureblob",
                "id": "<snip>"
            },
            "slack": {
                "connectionId": "<snip>",
                "connectionName": "slack",
                "id": "<snip>"
            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@base64ToString(body('Get_blob_content').$content)",
                "runAfter": {
                    "Get_blob_content": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Condition_2": {
                "actions": {
                    "Condition_3": {
                        "actions": {
                            "Delete_blob_3": {
                                "inputs": {
                                    "host": {
                                        "connection": {
                                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                                        }
                                    },
                                    "method": "delete",
                                    "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                },
                                "runAfter": {},
                                "type": "ApiConnection"
                            }
                        },
                        "else": {
                            "actions": {
                                "Copy_blob_2": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/datasets/default/copyFile",
                                        "queries": {
                                            "destination": "/<some-blob-container>/@{triggerBody()?['Name']}",
                                            "overwrite": false,
                                            "queryParametersSingleEncoded": true,
                                            "source": "@triggerBody()?['Path']"
                                        }
                                    },
                                    "runAfter": {
                                        "Post_message_2": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "ApiConnection"
                                },
                                "Delete_blob_4": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                                            }
                                        },
                                        "method": "delete",
                                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                    },
                                    "runAfter": {
                                        "Copy_blob_2": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "ApiConnection"
                                },
                                "Post_message_2": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['slack']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/chat.postMessage",
                                        "queries": {
                                            "channel": "<snip>",
                                            "text": "<some-message>"
                                        }
                                    },
                                    "runAfter": {},
                                    "type": "ApiConnection"
                                }
                            }
                        },
                        "expression": {
                            "or": [
                                {
                                    "equals": [
                                        "@outputs('HTTP_2')['statusCode']",
                                        200
                                    ]
                                },
                                {
                                    "equals": [
                                        "@outputs('HTTP_2')['statusCode']",
                                        202
                                    ]
                                }
                            ]
                        },
                        "runAfter": {
                            "HTTP_2": [
                                "Succeeded",
                                "Failed"
                            ]
                        },
                        "type": "If"
                    },
                    "HTTP_2": {
                        "inputs": {
                            "authentication": {
                                "password": "<some-password>",
                                "type": "Basic",
                                "username": "<some-username>"
                            },
                            "body": "@outputs('Compose')",
                            "headers": {
                                "Content-Type": "application/json"
                            },
                            "method": "POST",
                            "uri": "<some-url>"
                        },
                        "runAfter": {},
                        "type": "Http"
                    }
                },
                "else": {
                    "actions": {
                        "Condition_4": {
                            "actions": {
                                "Delete_blob_5": {
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                                            }
                                        },
                                        "method": "delete",
                                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                    },
                                    "runAfter": {},
                                    "type": "ApiConnection"
                                }
                            },
                            "else": {
                                "actions": {
                                    "Copy_blob_3": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                                }
                                            },
                                            "method": "post",
                                            "path": "/datasets/default/copyFile",
                                            "queries": {
                                                "destination": "/<some-blob-container>/@{triggerBody()?['Name']}",
                                                "overwrite": false,
                                                "queryParametersSingleEncoded": true,
                                                "source": "@triggerBody()?['Path']"
                                            }
                                        },
                                        "runAfter": {
                                            "Post_message_3": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "ApiConnection"
                                    },
                                    "Delete_blob_6": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['azureblob']['connectionId']"
                                                }
                                            },
                                            "method": "delete",
                                            "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}"
                                        },
                                        "runAfter": {
                                            "Copy_blob_3": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "ApiConnection"
                                    },
                                    "Post_message_3": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['slack']['connectionId']"
                                                }
                                            },
                                            "method": "post",
                                            "path": "/chat.postMessage",
                                            "queries": {
                                                "channel": "<snip>",
                                                "text": "<some-message>"
                                            }
                                        },
                                        "runAfter": {},
                                        "type": "ApiConnection"
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@outputs('HTTP_3')['statusCode']",
                                            200
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@outputs('HTTP_3')['statusCode']",
                                            202
                                        ]
                                    }
                                ]
                            },
                            "runAfter": {
                                "HTTP_3": [
                                    "Succeeded"
                                ]
                            },
                            "type": "If"
                        },
                        "HTTP_3": {
                            "inputs": {
                                "authentication": {
                                    "password": "<some-password>",
                                    "type": "Basic",
                                    "username": "<some-username>"
                                },
                                "body": "@outputs('Compose')",
                                "headers": {
                                    "Content-Type": "application/json"
                                },
                                "method": "POST",
                                "uri": "<some-url>"
                            },
                            "runAfter": {},
                            "type": "Http"
                        }
                    }
                },
                "expression": {
                    "and": [
                        {
                            "contains": [
                                "@outputs('Compose')",
                                "\"CustomerId\":\"00000000-0000-0000-0000-000000000000\""
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Get_blob_content": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Path']))}/content",
                    "queries": {
                        "inferContentType": true
                    }
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "When_a_blob_is_added_or_modified_(properties_only)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/default/triggers/batch/onupdatedfile",
                    "queries": {
                        "folderId": "<some-generated-folderid>",
                        "maxFileCount": 100
                    }
                },
                "metadata": {
                    "<some-generated-folderid>": "/<some-blob-container>"
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 1
                },
                "splitOn": "@triggerBody()",
                "type": "ApiConnection"
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.