【问题标题】:JSON format when using Marketo REST API to create Custom Object record使用 Marketo REST API 创建自定义对象记录时的 JSON 格式
【发布时间】:2023-03-15 22:00:02
【问题描述】:

我正在尝试使用其余 API 创建自定义对象记录,但我不确定我的 JSON 对象应该是什么样子。我有两个字段需要重复数据删除(personIDemailAddress),然后是几个字段(question01, question02

看这里我可以看到将 JSON 发送到哪里,但我不明白格式应该是什么样子。我将使用 jQuery 的 ajax 函数发布数据 http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Custom_Objects/syncCustomObjectsUsingPOST

我也不明白何时或如何获得新令牌。也许这应该是另一个线程。

【问题讨论】:

    标签: jquery json rest marketo


    【解决方案1】:

    第一件事
    除非您使用 jQuery under node.js,否则您将无法使用客户端 javascript 访问 Marketo REST API,因为这些请求将因 CORS 而被阻止。 此外,生成Access Token 所需的Client Secret 在客户端将不再保密。因此,您必须从您的服务器执行此操作。

    有效载荷
    有问题的有效负载在 API 文档的 REST API / Lead Database / Custom Objects 部分中有更好的记录。
    在您的情况下,它看起来像这样:

    {
        'action'    : 'createOrUpdate',// optional
        'dedupeBy'  : 'dedupeFields',// optional
        // input is an array of objects containing the custom object fields
        'input'     : [
            {
                'personID'      : 'personID',
                'emailAddress'  : 'emailAddress',
                'question01'    : 'question01 value',
                'question02'    : 'question02 value'
            },
            // …Other items…
        ]
    }
    

    应该在请求的 body 中。下面的示例代码说明了您将如何使用 jQuery 执行此操作,但同样,它无法从客户端运行。

    var instanceId = '123-ABC-456',
        accessToken = 'ACCESS_TOKEN',
        customObjectName = 'customObjectName_c',
        payload = payloadFromAbove;
    
    $.ajax({
        // Constructing url with ES6 String Interpolation
        url: `https://${instanceId}.mktorest.com/rest/v1/customobjects/${customObjectName}.json?access_token=${accessToken}`,
        method: 'POST',
        data: JSON.stringify(payload),
        dataType: 'json',
    })
    .done(function(response) {
        console.log(response);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      相关资源
      最近更新 更多