0
votes

I have a logic app which is triggered by an HTTP call. With this call comes a set of headers, most of them used in different switch statements. Using the Parse JSON action I feed in the headers from the request, they successfully parse (image 1), but for one of the headers (searchType) the switch statement evaluates to null for some reason (image 2). I cannot for the life of me figure out why.

I have tried to remake the logic app from scratch, copy the app to a different environment entirely, and tried to use the expression to access the parsed value instead of dynamic content. When I try the expression I am told it is an invalid expression (image 3). This expression is a straight copy from what is used on the code view.

Any suggestions as to what i can do to solve this?

Successful parsing of headers

enter image description here

parsed header evaluates to null

enter image description here

expression invalid

enter image description here

JSON to replicate logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "HeadersJson": {
                "inputs": {
                    "content": "@triggerOutputs()['headers']",
                    "schema": {
                        "properties": {
                            "APICallFor": {
                                "type": "string"
                            },
                            "Accept-Encoding": {
                                "type": "string"
                            },
                            "Accept-Language": {
                                "type": "string"
                            },
                            "Connection": {
                                "type": "string"
                            },
                            "Content-Length": {
                                "type": "string"
                            },
                            "Content-Type": {
                                "type": "string"
                            },
                            "Host": {
                                "type": "string"
                            },
                            "User-Agent": {
                                "type": "string"
                            },
                            "searchType": {
                                "type": "string"
                            },
                            "x-ms-action-tracking-id": {
                                "type": "string"
                            },
                            "x-ms-activity-vector": {
                                "type": "string"
                            },
                            "x-ms-client-request-id": {
                                "type": "string"
                            },
                            "x-ms-client-tracking-id": {
                                "type": "string"
                            },
                            "x-ms-correlation-id": {
                                "type": "string"
                            },
                            "x-ms-execution-location": {
                                "type": "string"
                            },
                            "x-ms-tracking-id": {
                                "type": "string"
                            },
                            "x-ms-workflow-id": {
                                "type": "string"
                            },
                            "x-ms-workflow-name": {
                                "type": "string"
                            },
                            "x-ms-workflow-operation-name": {
                                "type": "string"
                            },
                            "x-ms-workflow-resourcegroup-name": {
                                "type": "string"
                            },
                            "x-ms-workflow-run-id": {
                                "type": "string"
                            },
                            "x-ms-workflow-run-tracking-id": {
                                "type": "string"
                            },
                            "x-ms-workflow-subscription-id": {
                                "type": "string"
                            },
                            "x-ms-workflow-system-id": {
                                "type": "string"
                            },
                            "x-ms-workflow-version": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            },
            "Switch": {
                "cases": {
                    "Get_Departments": {
                        "actions": {
                            "Switch_3": {
                                "cases": {
                                    "Case": {
                                        "actions": {
                                            "Response_5": {
                                                "inputs": {
                                                    "body": "got to individual",
                                                    "statusCode": 200
                                                },
                                                "kind": "Http",
                                                "runAfter": {},
                                                "type": "Response"
                                            }
                                        },
                                        "case": "individual"
                                    },
                                    "Case_2": {
                                        "actions": {
                                            "Response": {
                                                "inputs": {
                                                    "body": "got to bulk",
                                                    "statusCode": 200
                                                },
                                                "kind": "Http",
                                                "runAfter": {},
                                                "type": "Response"
                                            }
                                        },
                                        "case": "bulk"
                                    }
                                },
                                "default": {
                                    "actions": {
                                        "Response_3": {
                                            "inputs": {
                                                "body": "the searchType parameter is not valid",
                                                "statusCode": 200
                                            },
                                            "kind": "Http",
                                            "runAfter": {},
                                            "type": "Response"
                                        }
                                    }
                                },
                                "expression": "@body('HeadersJson')?['serachType']",
                                "runAfter": {},
                                "type": "Switch"
                            }
                        },
                        "case": "departments"
                    }
                },
                "default": {
                    "actions": {
                        "Response_2": {
                            "inputs": {
                                "body": "the APICallFor header is not valid",
                                "statusCode": 500
                            },
                            "kind": "Http",
                            "runAfter": {},
                            "type": "Response"
                        }
                    }
                },
                "expression": "@body('HeadersJson')?['APICallFor']",
                "runAfter": {
                    "HeadersJson": [
                        "Succeeded"
                    ]
                },
                "type": "Switch"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {
                        "properties": {
                            "searchString": {
                                "type": "string"
                            },
                            "searchType": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "kind": "Http",
                "operationOptions": "EnableSchemaValidation",
                "type": "Request"
            }
        }
    }
}
1

1 Answers

3
votes

Your expression is invalid is because the @ in your expression, the @ expression is used in Code view, it should just be body('HeadersJson')?['searchType'].

As for your searchType is null, it's probably the ParseJson schema is not correct, so please make sure the right schema as the doc way.

And if you want to use the header data, you don't need parse the header to json, cause the data is already in json format, however if you pass data with request body you will need to parse it. Also i have test it, it will work with triggerOutputs()['headers']['searchType'], so just paste it in the expression, if you use code view, it will be @triggerOutputs()['headers']['searchType'].

enter image description here

enter image description here