我们如何使用 Marketo REST API 记录针对潜在客户的自定义 Activity 数据?

How can we log Custom Activity data against leads with Marketo REST API?

我们已经使用 Marketo 门户网站创建了自定义 Activity,并且我们能够使用 REST API 创建销售线索。那么现在,我们如何使用 Marketo REST API 记录自定义 Activity 数据?
自定义Activity结构如下:

{
    "id": 100001,
    "name": "TEST_ACTIVITY",
    "apiName": "test_api_c",
    "description": "",
    "primaryAttribute": {
        "name": "event_id",
        "apiName": "event_id",
        "dataType": "string"
    },
    "attributes": [
        {
            "name": "email",
            "apiName": "email",
            "dataType": "email"
        },
        {
            "name": "event_data",
            "apiName": "event_data",
            "dataType": "string"
        }
    ]
}

您可以将自定义 activity 记录推送到 Add Custom Activities 端点,该端点位于 POST /rest/v1/activities/external.json url.

首先,值得注意的是,为了使用端点,API 用户必须拥有“Read-Write Activity”权限。
端点需要一个带有单个 input 键的负载,最多可容纳 300 activity 条记录。对于每个 activity 记录 leadIdactivityDateactivityTypeIdprimaryAttributeValueattributes 字段是必需的,在属性数组的情况下,name 是正常的“名称”字段,而不是“apiName”。

在您的情况下,有效载荷看起来像这样:

{  
    "input":[// Note the array of records
        {
            "activityDate":"2018-03-20T22:43:12+02:00",
            "activityTypeId":100001,
            "leadId":<LEAD_ID>,
            "primaryAttributeValue":"<YOUR_EVENT_ID>",
            "attributes":[
                {
                    "name":"email",// This is the `name` field of the attribute, not the `apiName`!
                    "value":"<EMAIL_ADDRESS>"
                },
                {
                    "name":"event_data",// This is the `name` field of the attribute, not the `apiName`!
                    "value":"<EVENT_DATA>"
                }
            ]
        },
        //{
        //  …other activity records…
        //}
    ]
}