4
votes

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.

1
Can you try without the array (Values: "296e5e0a-ffe1-e944-80f4-005166811dbb")?jasonscript
@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
When I try "Values": [ {"Value":"myGuid" } ] I get a different error: "No parameterless constructor defined for this object"jasonscript
@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
@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 actually lists the valid properties for that object.Francis Gagnon

1 Answers

2
votes

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).