How can we help?

Update Contact Attribute or List Values

In this article:

Using Smarty utilities, you are able to update contact attributes and list values when a message is sent.

Note: These updates take place at render time during the sending process as opposed to open time or message preview.
Note: Contact data uploaded to or otherwise stored at Cordial is replicated to a secondary data layer to facilitate speed and availability. This replication process typically ensures data consistency within 30 seconds, dependent upon update frequency and volume. Updates made to contact records (new or existing) may not be immediately available, and we recommend waiting 30-60 seconds before issuing a query for recently updated information.

Use the following code to run the Smarty function. Replace attribute_key with the desired attribute to be updated and new_attribute_value with the new value.

{$utils->updateContact(['attribute_key'=>'new_attribute_value'])}

Update Contact Attributes

Subscribe Status

Update contact's subscribe status

{$utils->updateContact(['channels'=>['email'=>['subscribeStatus'=>'subscribed']]])}

The above will update the contact's email subscribeStatus attribute to "subscribed".

String Attributes

Update a String Attribute

{$utils->updateContact(['flavor'=>'chocolate'])}

The above will update the contact's flavor attribute to "chocolate".

Use external variables to update contact attribute

You can pass an external variable in your message using {$extVars.variableName} and then add the variable data to a contact attribute of your choice:

{$utils->updateContact(['flavor'=>{$extVars.chocolate}])}

The above will update the contact's flavor attribute with data passed as external variable.

Number Attributes

Update a Number Attribute

{$utils->updateContact(['viewed'=>'3'])}

The above will update the contact's viewed attribute to "3".

Increment and Decrement Number Attributes

Increment a number

{$utils->updateContact(['total'=>['inc' => '+1']])}

The above will update a contact's total attribute by "+1".

Decrement a number

{$utils->updateContact(['viewed'=>['inc' => '-1']])}

The above will update a contact's viewed attribute by "-1".

Array Attributes

Update an Array Attribute

{$utils->updateContact(['fav_fruit'=>['banana']])}

The above will update the contact's fav_fruit array attribute with the value of "banana". Note that all existing array values will be overwritten.

{$utils->updateContact(['fav_fruit'=>['banana','apple']])}

The above will update the contact's fav_fruit array attribute with the values of "banana" and "apple". Note that all existing array values will be overwritten.

Add Values To an Array Attribute

{$utils->updateContact(['fav_fruit'=>['add' => ['orange','strawberry']]])}

The above will add the values "orange" and "strawberry" to the contact's fav_fruit array attribute. Existing values will be retained unless the max items limit is exceeded. 

Note: If the number of array values exceeds the max items limit (default 25), the oldest values will be replaced with the newest values. The max items limit can be set using a POST or PUT Account Contact Attributes API call.

Remove Values From an Array Attribute

{$utils->updateContact(['fav_fruit'=>['remove' => ['orange','strawberry']]])}

The above will remove the values "orange" and "strawberry" from the contact's fav_fruit array attribute. 

Update list membership

You can add or remove a contact to a specified list with the following code by replacing mylist with the name of the list to be updated and either true (on the list) or false (off the list).

Note: The value true or false is a boolean value and is written in Smarty without quotes.
{$utils->updateContact(['mylist'=>true])}

Add to a list

{$utils->updateContact(['weekly-specials'=>true])}

This will add the contact to the "weekly-specials" list.

You can add the contact to more than one list by separating the key/value pairs by a comma: ['weekly-specials'=>true,'monthly-specials'=>true].

Remove from a list

{$utils->updateContact(['weekly-specials'=>false])}

This will remove the contact from the "weekly-specials" list.

You can remove the contact from more than one list by separating the key/value pairs by a comma: ['weekly-specials'=>false,'monthly-specials'=>false].

Combining multiple update functions

You are able to combine multiple update functions into one tag.

{$utils->updateContact(['flavor'=>'vanilla','age'=>['inc' => '+1']])}

This will update the contact's flavor attribute to "vanilla" and increment the age attribute "+1".

Note: The $util->updateContact() method is ignored by test messages so it is necessary to send a live message in order to use the method.  

In the next article learn about using webhooks.

Comments

0 comments

Please sign in to leave a comment.