Azure Logic App POST request to Microsoft Graph API succeeds manually but fails when invoked externally via webhook

I’m experiencing an issue with an Azure Logic App (Consumption) where a POST request to the Microsoft Graph API for appRoleAssignment works perfectly when I manually resubmit the failed action, but fails when the Logic App is triggered externally via a webhook.

Here are the details of my setup and the issue:

Logic App Configuration

  • HTTP Action Configuration:
{
  "method": "POST",
  "uri": "https://graph.microsoft.com/v1.0/servicePrincipals/{appObjectId}/appRoleAssignments",
  "headers": {
    "Authorization": "Bearer <access_token>",
    "Content-Type": "application/json"
  },
  "body": {
    "principalId": "user-or-service-principal-id",
    "resourceId": "resource-service-principal-id",
    "appRoleId": "app-role-id"
  },
  "retryPolicy": {
    "type": "fixed",
    "interval": "PT5S",
    "count": 3
  },
  "timeout": "PT30S"
}

Error Message
When the Logic App is triggered via a webhook, the request fails with the following error:

{
  "error": {
    "code": "Request_BadRequest",
    "message": "Not a valid reference update.",
    "innerError": {
      "date": "2024-07-18T14:21:29",
      "request-id": "ac44f253-5bbf-48bf-8c8e-c81603fd1320",
      "client-request-id": "ac44f253-5bbf-48bf-8c8e-c81603fd1320"
    }
  }
}

Payload and Headers

  • Request Payload:
{
  "principalId": "user-or-service-principal-id",
  "resourceId": "resource-service-principal-id",
  "appRoleId": "app-role-id"
}

  • Headers:
{
  "Authorization": "Bearer <access_token>",
  "Content-Type": "application/json"
}

Observations

  • The POST requestworks when I manually resubmit the action within the Logic App (from run history).
  • The same request fails when triggered externally via a webhook.
  • The access token, payload, URI, and headers are verified to be correct.
  • The error message suggests a BadRequest due to an invalid reference update.

What could be causing the POST request to fail when the Logic App is invoked externally via a webhook but succeed when manually resubmitted?

I have added logging actions in the Logic App to capture the state before and after the HTTP request. Here is the relevant part of my Logic App flow:

{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
      "LogBefore": {
        "inputs": {
          "message": "Before HTTP Request: @string(body('WebhookTrigger'))"
        },
        "runAfter": {},
        "type": "Compose"
      },
      "HTTP": {
        "inputs": {
          "method": "POST",
          "uri": "https://graph.microsoft.com/v1.0/servicePrincipals/{appObjectId}/appRoleAssignments",
          "headers": {
            "Authorization": "Bearer <access_token>",
            "Content-Type": "application/json"
          },
          "body": {
            "principalId": "user-or-service-principal-id",
            "resourceId": "resource-service-principal-id",
            "appRoleId": "app-role-id"
          },
          "retryPolicy": {
            "type": "fixed",
            "interval": "PT5S",
            "count": 3
          },
          "timeout": "PT30S"
        },
        "runAfter": {
          "LogBefore": [
            "Succeeded"
          ]
        },
        "type": "Http"
      },
      "LogAfter": {
        "inputs": {
          "message": "After HTTP Request: @string(outputs('HTTP'))"
        },
        "runAfter": {
          "HTTP": [
            "Succeeded"
          ]
        },
        "type": "Compose"
      }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "triggers": {
      "WebhookTrigger": {
        "inputs": {},
        "kind": "Http",
        "type": "Request"
      }
    }
  },
  "parameters": {}
}

Webhook Request Payload (captured in logs before the HTTP action)

{
  "principalId": "user-or-service-principal-id",
  "resourceId": "resource-service-principal-id",
  "appRoleId": "app-role-id"
}

Webhook Request Headers (captured in logs):

{
  "Authorization": "Bearer <access_token>",
  "Content-Type": "application/json"
}

Update (2024-07-18 18:00):
Upon further investigation, I found that –

  • IT FAILS: When I store the appRoleId (a GUID) in a variable and dynamically pass its value to the payload body, then the request fails.
  • IT WORKS: If I hard code the GUID for appRoleId in the body itself, then it works (I have copied and pasted the value from the variable).

My guess is that HTTP request to the Graph API is being fired before the Logic App has correctly evaluated the value of the variable.

Update (2024-07-18 18:25): Another interesting fact I forgot to mention is adding retries doesn’t work here, because the error returned in 400. And even if I hard code the GUID of appRoleId in the payload body, it still fails unless I add a delay of at least 25 seconds and then retry the action further down after getting a 400 error. See the screenshot below.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật