对讲机:如何在联系人上创建自定义属性?
Intercom: How can i create a custom attribute on a contact?
我正在使用 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.data_attributes.create({ name: "kamil_attribute", model: "contact", data_type: "string" })
如果该属性当前不存在,API docs mention that need to create it first
Creating new Custom Data Attributes
You can only write to custom data attributes that already exist on the workspace. If you need to create new attributes to write to, you should Create Data Attributes through the Data Attributes API.
请注意,访问令牌需要权限才能创建属性,因此如果您当前没有权限,您可能需要添加权限,然后重新生成令牌,然后在任何代码中更新令牌值正在使用
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)
如果属性存在,它会抛出一个错误,所以你可以在创建之前检查属性是否存在,或者当你捕获异常时创建属性是否有错误,然后重试更新。
我正在使用 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.data_attributes.create({ name: "kamil_attribute", model: "contact", data_type: "string" })
如果该属性当前不存在,API docs mention that need to create it first
Creating new Custom Data Attributes
You can only write to custom data attributes that already exist on the workspace. If you need to create new attributes to write to, you should Create Data Attributes through the Data Attributes API.
请注意,访问令牌需要权限才能创建属性,因此如果您当前没有权限,您可能需要添加权限,然后重新生成令牌,然后在任何代码中更新令牌值正在使用
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)
如果属性存在,它会抛出一个错误,所以你可以在创建之前检查属性是否存在,或者当你捕获异常时创建属性是否有错误,然后重试更新。