繁体   English   中英

Dynamics 365 Web API - 如何使用 web ZDB9444238D104CADE1 注册 webhook 的步骤

[英]Dynamics 365 Web API - How can I register a step for a webhook using the web API?

我正在探索 Dynamics CRM web API 并尝试注册一个将在更新/创建实体(如联系人/帐户)时触发的 webhook。 我可以使用 PluginRegistration 工具创建此设置,但我想将该工具从我的工作流程中排除。 如果可能,我想通过 web API 注册 webhook 和步骤。 我能够成功注册 webhook - 使用对以下端点的 POST 请求:

/api/data/v9.0/serviceendpoints

具有以下主体:

{
    "name":"Test Webhook",
    "url":"http://somewebhookendpoint.somedomain.com",
    "contract":8,
    "authtype":4,
    "authvalue":"args"
}

但是,当尝试创建sdkmessageprocessingstep (我假设这是我尝试在此 webhook 下创建的步骤)时,我收到400 Bad Request错误。 这是我传递给 sdkmessageprocessingstep 创建端点的请求正文(api/data/v9.0/sdkmessageprocessingsteps)

{
        "name":"Test for Step Creation",
        "stage":40,
        "rank":1,
        "eventhandlerid":"04e08d50-e63b-eb11-a813-000d3a0a7552",
        "sdkmessageid":"9ebdbb1b-ea3e-db11-86a7-000a3a5473e8",
        "sdkmessagefilterid": "c2c5bb1b-ea3e-db11-86a7-000a3a5473e8",
        "supporteddeployment":0,
        "description":"TEST FOR STEP CREATION #1"
}

但是在传递此请求后,我收到以下错误(这似乎表明我没有以正确的格式发送sdkmessageid )。

{
    "error": {
        "code": "0x0",
        "message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: A 'PrimitiveValue' node with non-null value was found when trying to read the value of the property 'sdkmessageid'; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.\r\n   at Microsoft.OData.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ValidateExpandedNestedResourceInfoPropertyValue(IJsonReader jsonReader, Nullable`1 isCollection, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadPropertyWithValue(IODataJsonLightReaderResourceState resourceState, String propertyName, Boolean isDeltaResourceSet)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.<>c__DisplayClass9_0.<ReadResourceContent>b__0(PropertyParsingResult propertyParsingResult, String propertyName)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ProcessProperty(PropertyAndAnnotationCollector propertyAndAnnotationCollector, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightResourceDeserializer.ReadResourceContent(IODataJsonLightReaderResourceState resourceState)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.StartReadingResource()\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadResourceSetItemStart(PropertyAndAnnotationCollector propertyAndAnnotationCollector, SelectedPropertiesNode selectedProperties)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementationSynchronously(PropertyAndAnnotationCollector propertyAndAnnotationCollector)\r\n   at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n   at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n   at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"
    }
}

我不确定应该如何传递eventhandlerid,sdkmessageid & sdkmessagefilterid 我尝试将它作为 object 传递 - 像这样:

{
        "name":"test through json",
        "stage":40,
        "rank":1,
        "EventHandler":{"@id":"04e08d50-e63b-eb11-a813-000d3a0a7552"},
        "SdkMessage":{"@id":"9ebdbb1b-ea3e-db11-86a7-000a3a5473e8"},
        "SdkMessageFilter": {"@id":"c2c5bb1b-ea3e-db11-86a7-000a3a5473e8"},
        "description":"TEST through JSON #1"
}

但无济于事(删除@也不起作用)。 响应似乎表明我传递了一些不正确的参数:

{
    "error": {
        "code": "0x0",
        "message": "An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.\r\n   at System.Web.OData.Formatter.Deserialization.DeserializationHelpers.ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, Object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)\r\n   at Microsoft.Crm.Extensibility.CrmODataEntityDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ReadResource(ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)\r\n   at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"
    }
}

有人可以通过指定如何使用 Dynamics Web API 在serviceendpoint端点下注册sdkmessageprocessingstep来提供帮助吗?

可能是单值导航属性(查找)分配问题的问题,但错误消息有点不同。

我还没有测试过这个有效载荷,所以请测试一下。 顺便说一句,CRM REST 构建器在这些场景中有助于构建 web api 片段。

{
        "name":"Test for Step Creation",
        "stage":40,
        "rank":1,
        "eventhandler_serviceendpoint@odata.bind":"/serviceendpoints(04e08d50-e63b-eb11-a813-000d3a0a7552)",
        "sdkmessageid@odata.bind":"/sdkmessages(9ebdbb1b-ea3e-db11-86a7-000a3a5473e8)",
        "sdkmessagefilterid@odata.bind": "/sdkmessagefilters(c2c5bb1b-ea3e-db11-86a7-000a3a5473e8)",
        "supporteddeployment":0,
        "description":"TEST FOR STEP CREATION #1"
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM