> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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: appendOrCreateContact(contactInfo: ContactInfo)

# Method package: wixCrmFrontend

# Method menu location: wixCrmFrontend --> Contacts --> appendOrCreateContact

# Method Link: https://dev.wix.com/docs/velo/apis/wix-crm-frontend/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 Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Append or create a contact with name

```javascript
import { contacts } from 'wix-crm-frontend';

// ...

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-crm-frontend';

// ...

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);
  });
```

---