Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posting a card to MS Teams channel returns PreconditionFailed-ETag mismatch for thread resource. #1163

Open
FlipFlop17 opened this issue Sep 13, 2024 · 2 comments

Comments

@FlipFlop17
Copy link

FlipFlop17 commented Sep 13, 2024

Describe the Bug with repro steps

Create a logic app standard workflow:

  1. Create a HTTP request triger that trigers on Devops US updates (webhook)

  2. Create a Post card in a chat or channel connector

{ "type": "ApiConnection", "inputs": { "host": { "connection": { "referenceName": "teams-1" } }, "method": "post", "body": { "recipient": { "groupId": "@{appsetting('sst626_teamId')}", "channelId": "@{appsetting('sst626_channelId')}" }, "messageBody": "@variables('AdaptiveCard')" }, "path": "/v1.0/teams/conversation/adaptivecard/poster/@{encodeURIComponent('User')}/location/@{encodeURIComponent('Channel')}", "retryPolicy": { "type": "exponential", "count": 30, "interval": "PT30S", "minimumInterval": "PT10S", "maximumInterval": "PT15M" } }, "runAfter": { "Switch": [ "Succeeded" ] }, "limit": { "timeout": "PT8M" } }

  1. The flow runs but sometimes returns an error:

PreconditionFailed-ETag mismatch for thread resource

What type of Logic App Is this happening in?

Standard (Portal)

Which operating system are you using?

Windows

Are you using new designer or old designer

New Designer

Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Init_workitemeditlink": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "WorkItemEditLink",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {}
            },
            "init_adaptive_card": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "AdaptiveCard",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Init_workitemeditlink": [
                        "SUCCEEDED"
                    ]
                }
            },
            "Post_card_in_a_chat_or_channel": {
                "type": "ApiConnection",
                "inputs": {
                    "host": {
                        "connection": {
                            "referenceName": "teams-1"
                        }
                    },
                    "method": "post",
                    "body": {
                        "recipient": {
                            "groupId": "@{appsetting('sst626_teamId')}",
                            "channelId": "@{appsetting('sst626_channelId')}"
                        },
                        "messageBody": "@variables('AdaptiveCard')"
                    },
                    "path": "/v1.0/teams/conversation/adaptivecard/poster/@{encodeURIComponent('User')}/location/@{encodeURIComponent('Channel')}",
                    "retryPolicy": {
                        "type": "exponential",
                        "count": 30,
                        "interval": "PT30S",
                        "minimumInterval": "PT10S",
                        "maximumInterval": "PT15M"
                    }
                },
                "runAfter": {
                    "Switch": [
                        "SUCCEEDED"
                    ]
                },
                "limit": {
                    "timeout": "PT8M"
                }
            },
            "Switch": {
                "type": "Switch",
                "expression": "@triggerBody()?['eventType']",
                "default": {
                    "actions": {
                        "Set_variable_undefined_type": {
                            "type": "SetVariable",
                            "inputs": {
                                "name": "AdaptiveCard",
                                "value": "{\n  \"type\": \"AdaptiveCard\",\n  \"body\": [\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"🚩 Notification from Azure DevOps\",\n      \"spacing\": \"Medium\",\n      \"size\": \"Large\",\n      \"weight\": \"Bolder\"\n    },\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"@{triggerBody()?['message']?['text']}\",\n      \"size\": \"Medium\",\n      \"spacing\": \"None\"\n    },\n    {\n      \"type\": \"FactSet\",\n      \"facts\": [\n        {\n          \"title\": \"Title\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.Title']}\"\n        },\n        {\n          \"title\": \"Type\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.WorkItemType']}\"\n        },\n        {\n          \"title\": \"Assigned to\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.AssignedTo']}\"\n        },\n        {\n          \"title\": \"Created time (UTC)\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.CreatedDate']}\"\n        }\n      ]\n    },\n    {\n      \"type\": \"ActionSet\",\n      \"actions\": [\n        {\n          \"type\": \"Action.OpenUrl\",\n          \"title\": \"View work item\",\n          \"url\": \"@{variables('WorkItemEditLink')}\"\n        }\n      ]\n    }\n  ],\n  \"version\": \"1.2\",\n  \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\"\n}"
                            }
                        }
                    }
                },
                "cases": {
                    "Case_deleted": {
                        "actions": {
                            "Set_card_deleted": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "AdaptiveCard",
                                    "value": "{\n  \"type\": \"AdaptiveCard\",\n  \"body\": [\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"🚩 Notification from Azure DevOps\",\n      \"spacing\": \"Medium\",\n      \"size\": \"Large\",\n      \"weight\": \"Bolder\"\n    },\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"@{json(outputs('Execute_JavaScript_Code-del'))[0]['textValRes']}\",\n      \"size\": \"Medium\",\n      \"spacing\": \"None\"\n    },\n    {\n      \"type\": \"FactSet\",\n      \"facts\": [\n        {\n          \"title\": \"Title\",\n          \"value\": \"@{json(outputs('Execute_JavaScript_Code-del'))[1]['titleValRes']}\"\n        },\n{\n          \"title\": \"Action\",\n          \"value\": \"@{replace(triggerBody()['eventType'],'.',' ')}\"\n        },\n        {\n          \"title\": \"Type\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.WorkItemType']}\"\n        },\n        {\n          \"title\": \"Assigned to\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.AssignedTo']}\"\n        },\n        {\n          \"title\": \"Created time (UTC)\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.CreatedDate']}\"\n        }\n      ]\n    },\n    {\n      \"type\": \"ActionSet\",\n      \"actions\": [\n        {\n          \"type\": \"Action.OpenUrl\",\n          \"title\": \"View work item\",\n          \"url\": \"@{variables('WorkItemEditLink')}\"\n        }\n      ]\n    }\n  ],\n  \"version\": \"1.2\",\n  \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\"\n}"
                                },
                                "runAfter": {
                                    "Execute_JavaScript_Code-del": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Set_edit_link_del": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "WorkItemEditLink",
                                    "value": "@concat('https://dev.azure.com/myorg/',triggerBody()?['resource']?['fields']?['System.TeamProject'],'/_workitems/edit/',triggerBody()?['resource']['id'])"
                                }
                            },
                            "Compose_text_val_d": {
                                "type": "Compose",
                                "inputs": "@triggerBody()?['message']?['text']",
                                "runAfter": {
                                    "Set_edit_link_del": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Compose__title_d": {
                                "type": "Compose",
                                "inputs": "@triggerBody()?['resource']?['fields']?['System.Title']",
                                "runAfter": {
                                    "Compose_text_val_d": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Execute_JavaScript_Code-del": {
                                "type": "JavaScriptCode",
                                "inputs": {
                                    "code": "let textVal=workflowContext.actions.Compose_text_val_d.outputs\r\nlet titleVal=workflowContext.actions.Compose__title_d.outputs\r\n\r\nlet textValRes=textVal.replace(/\\\\/g, '\\\\');\r\n textValRes=textValRes.replace(/\"/g, '');\r\n textValRes=textValRes.split(\"(https:\")[0].trim();\r\n \r\nlet titleValRes= titleVal.replace(/\"/g, '');\r\n titleValRes= titleValRes.replace(/\\\\/g, '\\\\');\r\n\r\nconst result = JSON.stringify([\r\n    {textValRes: textValRes},\r\n    {titleValRes: titleValRes},\r\n]);\r\n\r\nreturn result;"
                                },
                                "runAfter": {
                                    "Compose__title_d": [
                                        "SUCCEEDED"
                                    ]
                                }
                            }
                        },
                        "case": "workitem.deleted"
                    },
                    "Case_created": {
                        "actions": {
                            "Set_card_created": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "AdaptiveCard",
                                    "value": "{\n  \"type\": \"AdaptiveCard\",\n  \"body\": [\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"🚩 Notification from Azure DevOps\",\n      \"spacing\": \"Medium\",\n      \"size\": \"Large\",\n      \"weight\": \"Bolder\"\n    },\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"@{json(outputs('Execute_JavaScript_Code-creat'))[0]['textValRes']}\",\n      \"size\": \"Medium\",\n      \"spacing\": \"None\"\n    },\n    {\n      \"type\": \"FactSet\",\n      \"facts\": [\n        {\n          \"title\": \"Title\",\n          \"value\": \"@{json(outputs('Execute_JavaScript_Code-creat'))[1]['titleValRes']}\"\n        },\n{\n          \"title\": \"Action\",\n          \"value\": \"@{replace(triggerBody()['eventType'],'.',' ')}\"\n        },\n        {\n          \"title\": \"Type\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.WorkItemType']}\"\n        },\n        {\n          \"title\": \"Assigned to\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.AssignedTo']}\"\n        },\n        {\n          \"title\": \"Created time (UTC)\",\n          \"value\": \"@{triggerBody()?['resource']?['fields']?['System.CreatedDate']}\"\n        }\n      ]\n    },\n    {\n      \"type\": \"ActionSet\",\n      \"actions\": [\n        {\n          \"type\": \"Action.OpenUrl\",\n          \"title\": \"View work item\",\n          \"url\": \"@{variables('WorkItemEditLink')}\"\n        }\n      ]\n    }\n  ],\n  \"version\": \"1.2\",\n  \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\"\n}"
                                },
                                "runAfter": {
                                    "Execute_JavaScript_Code-creat": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Set_edit_link_cre": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "WorkItemEditLink",
                                    "value": "@concat('https://dev.azure.com/myorg/',triggerBody()?['resource']?['fields']?['System.TeamProject'],'/_workitems/edit/',triggerBody()?['resource']['id'])"
                                }
                            },
                            "Execute_JavaScript_Code-creat": {
                                "type": "JavaScriptCode",
                                "inputs": {
                                    "code": "let textVal=workflowContext.actions.Compose_text_val_c.outputs\r\nlet titleVal=workflowContext.actions.Compose__title_c.outputs\r\n\r\nlet textValRes=textVal.replace(/\\\\/g, '\\\\');\r\n textValRes=textValRes.replace(/\"/g, '');\r\n textValRes=textValRes.split(\"(https:\")[0].trim();\r\n \r\nlet titleValRes= titleVal.replace(/\"/g, '');\r\n titleValRes= titleValRes.replace(/\\\\/g, '\\\\');\r\n\r\nconst result = JSON.stringify([\r\n    {textValRes: textValRes},\r\n    {titleValRes: titleValRes},\r\n]);\r\n\r\nreturn result;"
                                },
                                "runAfter": {
                                    "Compose__title_c": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Compose_text_val_c": {
                                "type": "Compose",
                                "inputs": "@triggerBody()?['message']?['text']",
                                "runAfter": {
                                    "Set_edit_link_cre": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Compose__title_c": {
                                "type": "Compose",
                                "inputs": "@triggerBody()?['resource']?['fields']?['System.Title']",
                                "runAfter": {
                                    "Compose_text_val_c": [
                                        "SUCCEEDED"
                                    ]
                                }
                            }
                        },
                        "case": "workitem.created"
                    },
                    "Case_updated": {
                        "actions": {
                            "Set_card_updated": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "AdaptiveCard",
                                    "value": "{\n  \"type\": \"AdaptiveCard\",\n  \"body\": [\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"🚩 Notification from Azure DevOps\",\n      \"spacing\": \"Medium\",\n      \"size\": \"Large\",\n      \"weight\": \"Bolder\"\n    },\n    {\n      \"type\": \"TextBlock\",\n      \"text\": \"@{json(outputs('Execute_JavaScript_Code'))[0]['textValRes']}\",\n      \"size\": \"Medium\",\n      \"spacing\": \"None\"\n    },\n    {\n      \"type\": \"FactSet\",\n      \"facts\": [\n        {\n          \"title\": \"Title\",\n          \"value\": \"@{json(outputs('Execute_JavaScript_Code'))[1]['titleValRes']}\"\n        },\n{\n          \"title\": \"Action\",\n          \"value\": \"@{replace(triggerBody()['eventType'],'.',' ')}\"\n        },\n        {\n          \"title\": \"Type\",\n          \"value\": \"@{triggerBody()?['resource']?['revision']?['fields']?['System.WorkItemType']}\"\n        },\n        {\n          \"title\": \"Assigned to\",\n          \"value\": \"@{triggerBody()?['resource']?['revision']?['fields']?['System.AssignedTo']}\"\n        },\n        {\n          \"title\": \"Created time (UTC)\",\n          \"value\": \"@{triggerBody()?['resource']?['revision']?['fields']?['System.CreatedDate']}\"\n        }\n      ]\n    },\n    {\n      \"type\": \"ActionSet\",\n      \"actions\": [\n        {\n          \"type\": \"Action.OpenUrl\",\n          \"title\": \"View work item\",\n          \"url\": \"@{variables('WorkItemEditLink')}\"\n        }\n      ]\n    }\n  ],\n  \"version\": \"1.2\",\n  \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\"\n}"
                                },
                                "runAfter": {
                                    "Execute_JavaScript_Code": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Set_edit_link_upd": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "WorkItemEditLink",
                                    "value": "@concat('https://myorg/',triggerBody()?['resource']?['fields']?['System.TeamProject'],'/_workitems/edit/',triggerBody()?['resource']['workItemId'])"
                                }
                            },
                            "Execute_JavaScript_Code": {
                                "type": "JavaScriptCode",
                                "inputs": {
                                    "code": "let textVal=workflowContext.actions.Compose_text_val.outputs\r\nlet titleVal=workflowContext.actions.Compose__title.outputs\r\n\r\nlet textValRes=textVal.replace(/\\\\/g, '\\\\');\r\n textValRes=textValRes.replace(/\"/g, '');\r\n textValRes=textValRes.split(\"(https:\")[0].trim();\r\n\r\nlet titleValRes= titleVal.replace(/\"/g, '');\r\n titleValRes= titleValRes.replace(/\\\\/g, '\\\\');\r\n\r\nconst result = JSON.stringify([\r\n    {textValRes: textValRes},\r\n    {titleValRes: titleValRes},\r\n]);\r\n\r\nreturn result;"
                                },
                                "runAfter": {
                                    "Compose__title": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Compose_text_val": {
                                "type": "Compose",
                                "inputs": "@triggerBody()?['message']?['text']",
                                "runAfter": {
                                    "if_fo": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Compose__title": {
                                "type": "Compose",
                                "inputs": "@triggerBody()?['resource']?['revision']?['fields']?['System.Title']",
                                "runAfter": {
                                    "Compose_text_val": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "if_fo": {
                                "type": "If",
                                "description": "sometimes the theam pr. name is under a additional property (newValue)",
                                "expression": {
                                    "and": [
                                        {
                                            "contains": [
                                                "@variables('WorkItemEditLink')",
                                                "newValue"
                                            ]
                                        }
                                    ]
                                },
                                "actions": {
                                    "Set_clean_up_link": {
                                        "type": "SetVariable",
                                        "inputs": {
                                            "name": "WorkItemEditLink",
                                            "value": "@outputs('Compose_clean_up2')"
                                        },
                                        "runAfter": {
                                            "Compose_clean_up2": [
                                                "SUCCEEDED"
                                            ]
                                        }
                                    },
                                    "Compose_cleanup1": {
                                        "type": "Compose",
                                        "inputs": "@replace(variables('WorkItemEditLink'),'{\"newValue\":\"','')"
                                    },
                                    "Compose_clean_up2": {
                                        "type": "Compose",
                                        "inputs": "@replace(outputs('Compose_cleanup1'),'\"}','')",
                                        "runAfter": {
                                            "Compose_cleanup1": [
                                                "SUCCEEDED"
                                            ]
                                        }
                                    }
                                },
                                "else": {
                                    "actions": {}
                                },
                                "runAfter": {
                                    "Set_edit_link_upd": [
                                        "SUCCEEDED"
                                    ]
                                }
                            }
                        },
                        "case": "workitem.updated"
                    }
                },
                "runAfter": {
                    "init_adaptive_card": [
                        "SUCCEEDED"
                    ]
                }
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_a_HTTP_request_is_received": {
                "type": "Request",
                "kind": "Http"
            }
        }
    },
    "kind": "Stateful"
}

Screenshots or Videos

image

image

image

Browser

Edge

Additional context

Could this be a concurrency issue ?

@hartra344 hartra344 transferred this issue from Azure/LogicAppsUX Sep 13, 2024
Copy link

This issue is stale because it has been open for 45 days with no activity.

@github-actions github-actions bot added the stale label Oct 28, 2024
@AndreasRogge
Copy link

We have the same issue and currently have solved this with a check if this failed and make a retry. Then it works but this is not a nice solution

@github-actions github-actions bot removed the stale label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants