Dynamics CRM Web API 将市场营销列表添加到市场活动“"Association cannot be performed between an entity of type campaign and an entity of type list."”

Dynamics CRM Web API Add Marketing List to Campaign ""Association cannot be performed between an entity of type campaign and an entity of type list.""

当我尝试使用 Dynamics CRM Online Web API 在市场活动和营销列表之间建立联系时,我收到错误 "Association cannot be performed between an entity of type campaign and an entity of type list."。

我使用的是api

的V9.0

方法一:深插入

POST: {{webapiurl}}活动

正文:

 {
    "name": "test 2",

    "campaignlist_association": [

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

]

}

回应: {

"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", } } }

方法二:关联 POST: …/campaigns(000000000xxxxxx)/campaignlist_association/$ref

正文:

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

响应:

{ "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", } } }

结果 这两种方法都会产生相同的错误消息:"Association cannot be performed between an entity of type campaign and an entity of type list." 但是,当我在 Dynamics CRM UI 中关联它们并查询活动时,如果我展开 "campaignlist_association",我会准确地看到分配给活动的列表] 属性 通过网络 api.

许多本机 N-N 关系需要调用操作而不是关联 POST 请求来关联多个记录。您可以查看现成可用的 Web API 操作列表 here

在您的具体情况下,您需要在 POST 请求中调用 Microsoft.Dynamics.CRM.AddItemCampaign 操作,如下所示:

URL:

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

正文:

{
    "Campaign": {
        "campaignid": "YourCampaignGUID"
    }
}

试一试。我从我的邮递员那里导出了这个。将 {} 替换为您的值。

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"
    }
}'

这是一个例子:



您可以看到在动态中,数据已在我的活动中正确创建