UpsertContact()
Upserts attributes into a contact record. If the contact record exists, then it’s updated with the keys and values that you supply. If the contact doesn't exist, the function creates a contact using the keys and values that you supply.
The UpsertContact()
function has five parameters:
channel
(string): Required. The contact channel. The only supported value is "mobile".attribute
(string): Required. The attribute to use to match the contact. The only supported value is "phone".phoneNumber
(number): Required. The phone number of the contact. Include the country code.keyToUpsert1
(string): The name of the attribute to upsert.valueToUpsert1
(string): The value of the attribute to upsert.
The function can optionally upsert additional keys and values ([keyToUpsert2, valueToUpsert2 ...]
) by appending each key-value pair to the list of parameters. You can upsert as many keys and values as necessary in this way.
You can use this function to upsert any attribute that is part of the MobileConnect Data Attribute Group. These attributes include standard fields such as first name (_FirstName
), last name (_LastName
), and city (_City
), as well as custom attributes. You can view these attributes in the Data Designer in the Marketing Cloud Engagement web interface. For more information, see Data Designer in Contact Builder.
This example updates the system attribute _ZipCode
for the contact with the phone number 14255550142. It outputs 0
, indicating that the operation completed with no errors.
You can upsert several attributes at once. This example expands on the previous one by also updating the _FirstName
and _LastName
attributes.