> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name:

siteCrm.appendOrCreateContact(contactInfo: ContactInfo)

# Method Link:

https://dev.wix.com/docs/frontend-modules/frontend-modules/crm/contacts/append-or-create-contact.md

# Method Description:

Appends an existing contact or creates a contact if it doesn't exist.

The `appendOrCreateContact()` function returns a Promise
that resolves to a contact ID and identity type when a contact is found or created.

When called, `appendOrCreateContact()` accepts an object with contact information and follows the steps below.
When one of the conditions is met, this process ends and the specified
data is handled:

1. **If the current visitor is a logged-in member:** `appendOrCreateContact()` reconciles with the member's associated contact.
2. **If the visitor is not a logged-in member:** `appendOrCreateContact()` tries to reconcile any specified email addresses and/or phone numbers with an existing contact.
3. **If no contact can be reconciled in the previous steps:** `appendOrCreateContact()` tries to reconcile the visitor's session identity with an existing contact.
4. **If no contact can be reconciled and an email address, phone number, or name are provided:** A new contact is created and `appendOrCreateContact()` reconciles with the new contact.
5. **If no contact can be created:** The Promise is rejected.

`appendOrCreateContact()` does not require member authentication,
so it does not return the entire contact object.
The contact's data can be retrieved with
`getContact()` from the `crm` backend module ([SDK](https://dev.wix.com/docs/sdk/backend-modules/crm/contacts/get-contact.md) | [Velo](https://dev.wix.com/docs/velo/apis/wix-crm-backend/contacts/get-contact.md)).

#### How the Data Is Handled

If an **existing contact** is found:

- The current visitor's session identity is associated with the contact.
- If a specified property is empty in the existing contact, the property is updated with the specified information.
- For arrays, any specified information is added as new array items. This includes `emails`, `addresses`, `phones`, and `labelKeys`.
- No existing data is overwritten or deleted.

> **Note:**
> If the reconciled contact belongs to a member
> who isn't currently logged in to the site,
> `identityType` is returned as `"NOT_AUTHENTICATED_MEMBER"`.
> In that case, no contact properties are modified.

If a **new contact** is created:

- The new contact's data is populated with the specified contact object.
- The current visitor's session identity is associated with the contact.

# Method Permissions:



# Method Permissions Scopes IDs:

undefined



# Method Code Examples:

## Append or create a contact with name

```javascript
import { contacts } from '@wix/site-crm';

// ...

const contactInfo = {
  name: {
    first: "Ari",
    last: "Thereyet"
  }
};

contacts.appendOrCreateContact(contactInfo)
  .then((resolvedContact) => {
    return resolvedContact;
  })
  .catch((error) => {
    console.error(error);
  });
```

## Append or create a contact, full object

```javascript
import { contacts } from '@wix/site-crm';

// ...

const contactInfo = {
  name: {
    first: "Ari",
    last: "Thereyet"
  },
  emails: [
    {
      email: "ari.thereyet@example.com",
    },
    {
      email: "ari.thereyet.appended.email@example.com"
    }
  ],
  phones: [
    {
      tag: "MOBILE",
      countryCode: "US",
      phone: "601-081-124",
      primary: true
    }
  ]
};

contacts.appendOrCreateContact(contactInfo)
  .then((resolvedContact) => {
    return resolvedContact;
  })
  .catch((error) => {
    console.error(error);
  });
```