---
schema_version: "1"
id: 86cb833ea433265ea33ccc0d81a4f9acdc7a6cefc8ea95fe730a3c964e8594d4
title: UpsertContact()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/contacts/mc-ampscript-reference-contacts-upsert-contact.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-contacts/mc-ampscript-reference-contacts-upsert-contact.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6ecd04b4a6e436bb30616ccff4a7d18f507a808a205a008f4151183f771074fb
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# 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))
]%%
```
