# 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.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
UpsertContact(channel,
              attribute, phoneNumber,
              keyToUpsert1, valueToUpsert1,
              [keyToUpsert2, valueToUpsert2 ...] )
```

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.

## Usage

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](https://help.salesforce.com/s/articleView?id=mktg.mc_cab_data_designer.htm).

### Updating One Attribute

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.

```
%%[
  Set @result = UpsertContact('mobile',
                              'phone', 14255550142,
                              '_ZipCode', '98026')
  Output(v(@result))
]%%
```

### Updating Multiple Attributes

You can upsert several attributes at once. This example expands on the previous one by also updating the `_FirstName` and `_LastName` attributes.

```
%%[
  Set @result = UpsertContact('mobile',
                              'phone', 14255550142,
                              '_ZipCode', '98026',
                              '_FirstName', 'Li',
                              '_LastName', 'Zhang')
  Output(v(@result))
]%%
```
