使用 API 更新 Azure 逻辑应用程序的触发频率

Updating trigger frequency of Azure Logic App using API

我正在尝试使用 Azure Logic SDK 更新逻辑应用程序的重复频率和间隔,但失败并显示此错误消息

Microsoft.Rest.Azure.CloudException: The request to patch workflow 'kk-test-logic-app' is not supported. None of the fields inside the properties object can be patched.

这是一个代码片段,展示了我正在尝试做的事情。

    var workflow = await _client.Value.Workflows.GetAsync(resourceGroupName, workflowName);

    dynamic workflowDefinition = workflow.Definition;
    workflowDefinition.triggers[triggerName]["recurrence"] = JToken.FromObject(new { frequency = triggerFrequency, interval = triggerInterval });

    await _client.Value.Workflows.UpdateAsync(resourceGroupName, workflowName, workflow);

其中 _client 是 Lazy<LogicManagementClient>

这是我尝试更新的触发器的定义(使用 Fiddler 获得):

  "triggers": {
    "When_a_new_email_arrives": {
      "recurrence": {
        "frequency": "Hour",
        "interval": 2
      },
      "splitOn": "@triggerBody()?.value",
      "type": "ApiConnection",
      "inputs": {
        "host": {
          "api": {
            "runtimeUrl": "https://logic-apis-southindia.azure-apim.net/apim/office365"
          },
          "connection": {
            "name": "@parameters('$connections')['office365']['connectionId']"
          }
        },
        "method": "get",
        "path": "/Mail/OnNewEmail",
        "queries": {
          "folderPath": "Inbox",
          "importance": "Any"
        }
      }
    }
  }

请注意,我能够成功检索工作流、workflowRuns、workflowTriggers 等。只有更新操作失败。关于如何使用 SDK 更新工作流属性的任何想法?

更新: 正如 Amor-MSFT 在下面的评论中指出的那样,这是一个缺陷,作为一种解决方法,我目前正在使用 CreateOrUpdateAsync 而不是 UpdateAsync。 new defect 已在 GitHub 中创建,以引起 SDK 开发团队的注意。

The trigger currently executes every 30s checking if a new mail was received from a certain email address and is working well as expected. I'm trying to change the recurrence frequency from 30s to 2hours using the code I provided.

我创建了一个邮件触发器,如果​​我使用 invoke UpdateAsync 方法,我可以重现该问题。根据Azure Logic C# SDK的source code,根据响应消息,它发送了一个不支持的PATCH请求。将 HTTP 方法更改为 PUT 后,我可以更新工作流程。这是我用来发送 PUT 请求的示例代码。

string triggerName = "When_a_new_email_arrives";
string resourceGroupName = "my resourcegroup name";
string workflowName = "my-LogicApp";
string subscriptionID = "my-subscriptionID";
var workflow = await _client.Workflows.GetAsync(resourceGroupName, workflowName);

string url = string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Logic/workflows/{2}?api-version=2016-06-01",
    subscriptionID, resourceGroupName, workflowName);
HttpClient client = new HttpClient();
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, url);
message.Headers.Add("Authorization", "Bearer put your token here");
message.Headers.Add("Accept", "application/json");
message.Headers.Add("Expect", "100-continue");

dynamic workflowDefinition = workflow.Definition;
workflowDefinition.triggers[triggerName]["recurrence"] = JToken.FromObject(new { frequency = "Minute", interval = 20 });

string s = workflow.ToString();
string workflowString = JsonConvert.SerializeObject(workflow, _client.SerializationSettings);

message.Content = new StringContent(workflowString, Encoding.UTF8, "application/json");
await client.SendAsync(message);