4

I’m trying to call the BulkDelete() Action of the WebAPI (OData REST service) of an on premise Microsoft Dynamics CRM 365 (2016 / v8.2) instance.

For now I am still at the stage of trying to make the action work by using Postman. I am doing an HTTP POST to a URL similar to https://MY_CRM_SERVER/api/data/v8.2/BulkDelete() with the following body:

{
    JobName: "Test Bulk Delete 1",
    QuerySet: [{
        EntityName: "oo_thingstodelete",
        ColumnSet: {
            AllColumns: true
        },
        Distinct: false,
        Criteria: {
            FilterOperator: "And",
            Conditions: [{
                AttributeName: "oo_thingstodeleteid",
                Operator: "Equal",
                Values: [ "296e5e0a-ffe1-e944-80f4-005166811dbb" ]
            }]
        }
    }],
    StartDateTime: "2019-04-18T05:00:00Z",
    ToRecipients: [],
    CCRecipients: [],
    SendEmailNotification: false,
    RecurrencePattern: "",
    RunNow: true
}

This request body currently yields the error:

The property with name '' was found with a value node of type 'PrimitiveValue'; however, a complex value of type 'Microsoft.Dynamics.CRM.Object' was expected.

From what I can tell, this is because the “Values” property (under QuerySet / Criteria / Conditions) expects a collection of “Object ComplexType”. This is documented in the “ConditionExpression” page of the CRM WebAPI v8.

At this point I am assuming that the “Values” property needs to be given a value similar to the following (instead of a simple string value):

Values: [ {  “Value”: "296e5e0a-ffe1-e944-80f4-005166811dbb" }]

But if I POST the above body with this new “Values” property value I get the error:

The property 'Value' does not exist on type 'Microsoft.Dynamics.CRM.Object'. Make sure to only use property names that are defined by the type.

This feels like progress but it doesn’t tell me what property name I should be using instead. The CRM WebAPI documentation for the “Object ComplexType” doesn’t list any property names that I can use in this object and I haven’t found any sample code on how to use the BulkDelete action via WebAPI.

Note that there may be other issues with this request body. This is just my current roadblock.

Francis Gagnon
  • 3,545
  • 1
  • 16
  • 25
  • Can you try without the array (`Values: "296e5e0a-ffe1-e944-80f4-005166811dbb"`)? – jasonscript May 08 '19 at 07:04
  • 1
    @jasonscript - That is one of the many things I tried. It returns the error: `An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartArray' node was expected.`. – Francis Gagnon May 08 '19 at 14:22
  • When I try `"Values": [ {"Value":"myGuid" } ]` I get a different error: "No parameterless constructor defined for this object" – jasonscript May 09 '19 at 03:42
  • @jasonscript - I tried that one again and still get the error I mentioned in my post. The error you're getting sounds like a deserialization bug on the CRM side or something. Odd. – Francis Gagnon May 09 '19 at 11:45
  • Happens also in CRM online/for latests 9.1 endpoint. – Ondrej Svejdar May 13 '19 at 10:18
  • 1
    @OndrejSvejdar - Interesting. I was hoping that when we finally move to v9 we would have a solution. The [documentation for CRM v9 for the Object Complex Type](https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/object?view=dynamics-ce-odata-9) actually lists the valid properties for that object. – Francis Gagnon May 13 '19 at 14:59
  • This is just a guess based off error messages, but maybe they want `Values: [{"Values" : "296e5e0a-ffe1-e944-80f4-005166811dbb"}]` where "Values" is the field, and the contents are a sub-collection of the values themselves? so to be clear, passing multiple values wouldn't be `[{"Value" : "valA"},{"Value" : "valB"}]` it would instead be `[{"Values" : ["valA","valB"] }]` or something like that? My apologies if this is syntactically incorrect, I'm not well versed in this API style yet. – Philippe Haussmann May 13 '19 at 16:39
  • @PhilippeHaussmann - Doesn't look like it's working either. I get the error "The property 'Values' does not exist..." with that. – Francis Gagnon May 13 '19 at 16:48
  • Maybe try objectid or solutionid? And the original method, my idea seems to be wrong. https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/solutioncomponent?view=dynamics-ce-odata-9 – Philippe Haussmann May 13 '19 at 17:38

1 Answers1

2

What worked for me was to specify type of item in values array explicitly. I.E.:

Values: [{"Value":"296e5e0a-ffe1-e944-80f4-005166811dbb","Type":"System.Guid"}]

I have different version of CRM though (9.1).

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
  • Sadly this doesn't work in v8.2. I get the same "The property 'Value' does not exist..." error. At lease I'll know it works in 9.1. Thanks. – Francis Gagnon May 13 '19 at 16:33