【问题标题】:Intercom: How can i create a custom attribute on a contact?对讲:如何在联系人上创建自定义属性?
【发布时间】:2021-06-30 20:50:57
【问题描述】:

我正在使用 Ruby API,以下代码出错:

intercom_query = intercom.contacts.search('query': {'field': 'external_id', 'operator': '=', 'value': 1})
contact = intercom_query.first
contact.custom_attributes = {"kamil_attribute" => "here-iam-update-me"}
intercom.contacts.save(contact)

“(自定义属性'kamil_attribute_console'不存在)”

【问题讨论】:

    标签: intercom


    【解决方案1】:

    认为需要先尝试创建属性

    intercom.data_attributes.create({ name: "kamil_attribute", model: "contact", data_type: "string" })
    

    如果该属性当前不存在,API docs mention that need to create it first

    创建新的自定义数据属性

    您只能写入工作区中已存在的自定义数据属性。如果您需要创建要写入的新属性,您应该通过 Data Attributes API Create Data Attributes

    请注意,访问令牌需要权限才能创建属性,因此如果您当前没有权限,您可能需要添加该权限,然后重新生成令牌,然后更新正在使用的任何代码中的令牌值

    intercom-ruby readme on data attributes

    # Create a new custom data attribute
    intercom.data_attributes.create({ name: "test_attribute", model: "contact", data_type: "string" })
    
    # List all data attributes
    attributes = intercom.data_attributes.all
    attributes.each { |attribute| p attribute.name }
    
    # Update an attribute
    attribute = intercom.data_attributes.all.first
    attribute.label = "New label"
    intercom.data_attributes.save(attribute)
    
    # Archive an attribute
    attribute.archived = true
    intercom.data_attributes.save(attribute)
    

    如果属性存在,它会抛出错误,因此您可以在创建之前检查属性是否存在,或者当您捕获异常然后重试更新时创建属性是否有错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多