如何使用 "Dynamics 365 Web API" 注册带有 Auth Type=Http Header 的 webhook

Howto register a webhook with AuthType=HttpHeader using "Dynamics 365 Web API"

要在 Dynamics 365 上注册 webhook,有一个名为 Plug-in Registration (https://docs.microsoft.com/en-us/powerapps/developer/data-platform/register-web-hook) 的工具。

但是,我想自动化 webhook 注册过程,因此想使用 Web API 端点进行 webhook 注册:

/api/data/v9.2/serviceendpoints

我遇到的问题是 JSON 请求 body 中参数 authvalue 的值的设置,因为我想使用 Http Header authtype:

{
    "name": "Test Webhook",
    "url": "https://myendpoint",
    "contract": 8,
    "authtype": 5,
    "authvalue": "<========= ??? what comes here ???"
}

假设我想将此 header 发送到我的 webhook 端点:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

上面 JSON 中 authvalue 的值是多少? 根据 authvalue 的数据类型,该值应该是一个字符串,但是应该如何格式化?

如果我使用值 Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= 作为 authvalue, 当 webhook 被触发时,我在系统作业中收到以下错误:

Plugin Trace:

[Microsoft.Crm.ServiceBus: Microsoft.Crm.ServiceBus.WebhookPlugin] [ad9a4124-ab57-ec11-8f8f-6045bd8aed3b: Test for Step Creation]

Error Message:

System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: The webhook call failed because of invalid http headers in authValue. Check if the authValue format, header names and values are valid for your Service Endpoint entity. (Fault Detail is equal to Exception details: ErrorCode: 0x80050203 Message: The webhook call failed because of invalid http headers in authValue. Check if the authValue format, header names and values are valid for your Service Endpoint entity. TimeStamp: 2021-12-08T10:15:26.8637496Z -- Exception details: ErrorCode: 0x80040216 Message: Received exception when adding custom http headers: for OrgId:xxxxxx-925f-4958-9aee-xxxxxxxxxxxx, serviceEndpointId: c099d16c-a057-ec11-8f8f-6045bd8aed3b, name: Test Webhook, exception:System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at Microsoft.Crm.ServiceBus.WebhookClient.ExtractKe...).

对于 HtppHeader 身份验证类型,AuthValue 的键值对必须按以下 xml 格式设置:

<settings><setting name="Authorization" value="Basic dXNlcm5hbWU6cGFzc3dvcmQ=" /></settings>