Dynamics 365 Web API - 如何使用 Web API 为 webhook 注册一个步骤?
Dynamics 365 Web API - How can I register a step for a webhook using the web API?
我正在探索 Dynamics CRM 网络 API 并尝试注册一个将在实体(如 contacts/accounts)为 updated/created 时触发的网络钩子。我可以使用 PluginRegistration 工具创建此设置,但我想从我的工作流程中排除该工具。如果可能的话,我想注册 webhook 和 step through web API。我能够成功注册 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 create endpoint (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
应该如何通过。我尝试将其作为对象传递 - 如下所示:
{
"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
吗?
可能是单值导航问题 属性(查找)分配问题,但错误消息有点不同。
我还没有测试过这个payload,所以请测试一下。顺便说一句,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"
}
我正在探索 Dynamics CRM 网络 API 并尝试注册一个将在实体(如 contacts/accounts)为 updated/created 时触发的网络钩子。我可以使用 PluginRegistration 工具创建此设置,但我想从我的工作流程中排除该工具。如果可能的话,我想注册 webhook 和 step through web API。我能够成功注册 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 create endpoint (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
应该如何通过。我尝试将其作为对象传递 - 如下所示:
{
"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
吗?
可能是单值导航问题 属性(查找)分配问题,但错误消息有点不同。
我还没有测试过这个payload,所以请测试一下。顺便说一句,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"
}