1
votes

I am getting the error, "Association cannot be performed between an entity of type campaign and an entity of type list." when I try to use Dynamics CRM Online Web API to make a connection between a Campaign and a Marketing List.

I am using V9.0 of the api

Approach 1: deep insert

POST: {{webapiurl}}campaigns

Body:

 {
    "name": "test 2",

    "campaignlist_association": [

    {
        "listname":"test3", 
        "createdfromcode":2
    }

]

}

Response: {

"error": { "code": "0x80040203",

"message": "Association cannot be performed between an entity of type campaign and an entity of type list.", "innererror": { "message": "Association cannot be performed between an entity of type campaign and an entity of type list.", "type": "Microsoft.Dynamics.Solution.Common.CrmNotSupportedException", } } }

Approach 2: Association POST: …/campaigns(000000000xxxxxx)/campaignlist_association/$ref

Body:

{  
"@odata.id":"{{webapiurl}}/lists(11111111xxxxxxxx)"  
}

Response:

{ "error": { "code": "0x80040203",

"message": "Association cannot be performed between an entity of type campaign and an entity of type list.",

"innererror": { "message": "Association cannot be performed between an entity of type campaign and an entity of type list.", "type": "Microsoft.Dynamics.Solution.Common.CrmNotSupportedException", } } }

Results Both approaches yield the same error message: "Association cannot be performed between an entity of type campaign and an entity of type list." However, when if I relate them in the Dynamics CRM UI, and query campaigns I accurately see the list assigned to the campaign if I expand the "campaignlist_association" property via the web api.

2

2 Answers

1
votes

Many native N-N relationships require an action to be called instead of an association POST request to associate multiple records. You can check the available out of the box Web API actions list here

In your case in specific you need to call Microsoft.Dynamics.CRM.AddItemCampaign action in a POST request like this:

URL:

[Organization URI]/lists(YourMarketingListGUID)/Microsoft.Dynamics.CRM.AddItemCampaign

Body:

{
    "Campaign": {
        "campaignid": "YourCampaignGUID"
    }
}
0
votes

Give this a try. I exported this from my postman. Replace {} with your values.

curl --location --request POST 'https://{YOUR_ORGANIZATION_URL_HERE}/api/data/v9.0/lists({MARKETING_LIST_UUID})/Microsoft.Dynamics.CRM.AddItemCampaign' \
--header 'Authorization: Bearer {AUTHENTICATION_TOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Campaign": {
        "campaignid": "{CAMPAIGN_ID}",
        "@odata.type": "Microsoft.Dynamics.CRM.campaign"
    }
}'

Here's an example:

enter image description here

You can see that in dynamics the data was created properly inside my campaign

enter image description here

enter image description here