Как выполнить действие поиска для конечной точки odata

CRM 2016 предоставляет API odata/web и имеет функции и действия из коробки.

Я пытаюсь выполнить следующий запрос:

https://mycrmorg.com/api/data/v8.1/Search(AppointmentRequest=@request)?@request={"ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345","AnchorOffset":1,"UserTimeZoneCode":1,"RecurrenceDuration":0,"RecurrenceTimeZoneCode":1,"RequiredResources":{"ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"},"SearchWindowStart":"1754-01-01T00:00:00Z","SearchWindowEnd":"9999-12-30T23:59:59Z","SearchRecurrenceStart":null,"Duration":1,"Constraints":[],"Objectives":[],"NumberOfResults":1,"Sites":[]}

Более красивая версия json:

{
   "ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345",
   "AnchorOffset":1,
   "UserTimeZoneCode":1,
   "RecurrenceDuration":0,
   "RecurrenceTimeZoneCode":1,
   "RequiredResources":{
      "ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"
   },
   "SearchWindowStart":"1754-01-01T00:00:00Z",
   "SearchWindowEnd":"9999-12-30T23:59:59Z",
   "SearchRecurrenceStart":null,
   "Duration":1,
   "Constraints":[

   ],
   "Objectives":[

   ],
   "NumberOfResults":1,
   "Sites":[

   ]
}

Исключение, которое я получаю:

    {
  "error":{
    "code":"","message":"An unexpected 'StartObject' node was found for property named 'RequiredResources' when reading from the JSON reader. A 'StartArray' node was expected.","innererror":{
      "message":"An unexpected 'StartObject' node was found for property named 'RequiredResources' when reading from the JSON reader. A 'StartArray' node was expected.","type":"Microsoft.OData.Core.ODataException","stacktrace":"   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue, String propertyName, Nullable`1 isDynamicProperty)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.<>c__DisplayClass14.<ReadComplexValue>b__12(PropertyParsingResult propertyParsingResult, String propertyName)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightDeserializer.ProcessProperty(DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadComplexValue(IEdmComplexTypeReference complexValueTypeReference, String payloadTypeName, SerializationTypeNameAnnotation serializationTypeNameAnnotation, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue, String propertyName, Nullable`1 isDynamicProperty)\r\n   at Microsoft.OData.Core.UriParser.ODataUriConversionUtils.ConvertFromComplexOrCollectionValue(String value, IEdmModel model, IEdmTypeReference typeReference)\r\n   at Microsoft.OData.Core.UriParser.ODataUriUtils.ConvertFromUriLiteral(String value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.ParseComplexOrCollectionAlias(QueryToken queryToken, IEdmTypeReference parameterType, IEdmModel model)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.ParseAndBindParameterAliasValueExpression(BindingState bindingState, String aliasValueExpression, IEdmTypeReference parameterType)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.BindParameterAlias(BindingState bindingState, FunctionParameterAliasToken aliasToken)\r\n   at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.OData.Core.UriParser.Parsers.FunctionCallBinder.BindSegmentParameters(ODataUriParserConfiguration configuration, IEdmOperation functionOrOpertion, ICollection`1 segmentParameterTokens)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.TryBindingParametersAndMatchingOperationImport(String identifier, String parenthesisExpression, ODataUriParserConfiguration configuration, ICollection`1& boundParameters, IEdmOperationImport& matchingFunctionImport)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.TryCreateSegmentForOperationImport(String identifier, String parenthesisExpression)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.CreateFirstSegment(String segmentText)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.ParsePath(ICollection`1 segments)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n   at Microsoft.OData.Core.UriParser.ODataUriParser.Initialize()\r\n   at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath, ODataUriResolverSetttings resolverSettings, Boolean enableUriTemplateParsing)\r\n   at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)"
    }
  }
}

Я считаю, что может быть проблема с тем, как я кодирую RequiredResources. Что я делаю не так? Как отправить этот запрос в CRM?


person Alex Gordon    schedule 09.10.2017    source источник


Ответы (1)


Я считаю, что проблема может заключаться в том, что вы используете RequiredResources как объект, а не коллекцию, попробуйте изменить его на

"RequiredResources": [{
   "ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"
}],

Полный JSON

{
   "ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345",
   "AnchorOffset":1,
   "UserTimeZoneCode":1,
   "RecurrenceDuration":0,
   "RecurrenceTimeZoneCode":1,
   "RequiredResources": [{
      "ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"
   }],
   "SearchWindowStart":"1754-01-01T00:00:00Z",
   "SearchWindowEnd":"9999-12-30T23:59:59Z",
   "SearchRecurrenceStart":null,
   "Duration":1,
   "Constraints":[

   ],
   "Objectives":[

   ],
   "NumberOfResults":1,
   "Sites":[

   ]
}

Коллекция RequiredResources (RequiredResource ComplexType)

Взято из

https://msdn.microsoft.com/en-us/library/mt592984.aspx

Сообщение об ошибке на самом деле говорит вам, что синтаксический анализатор ожидал [ вместо { symbol/token.

person Santhos    schedule 09.10.2017