# Create or Append a Contact with code

**URL:** <https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202>\
**Category:** Ask the community\
**Tags:** wix-crm-backend, wix-auth, question, code\
**Created:** [October 13, 2025, 12:07pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202 "2025-10-13T12:07:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 13, 2025, 12:07pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/1 "2025-10-13T12:07:40Z")

</div>

**Question:** How to create, update or append a contact with a user’s input values

Created contacts should appear on the Dash in _Customers & Leads \> Contacts_ right? But nothing has worked yet even at a basic level

> **Attempts (all failed!) :**
>
> _Approach 1)_ Only front end code as per an older tutorial
> 
> ```javascript
> import { contacts } from 'wix-crm';
> 
> $w.onReady(function () {
> $w('#submitButton').onClick((event) => {
> const contactInfo = {
> name: {
> first: $w('#input7').value,
> last: "Thereyet"
> },
> emails: [{
> email: "gene.lopez@example.com"
> }]
> };
> 
> contacts.appendOrCreateContact(contactInfo)
> .then((resolvedContact) => {
> return resolvedContact;
> })
> .catch((error) => {
> console.error(error);
> });          
> })
> });
> 
> ```
> 
> _Approach 2)_ AI Velo Assistant on [Velo Docs](https://dev.wix.com/docs/velo)
> 
> ```javascript
> // Backend code - contacts.jsw
> import { contacts } from 'wix-crm.v2'; // Or 'wix-crm-backend'
> import { elevate } from 'wix-auth';
> import { webMethod, Permissions } from 'wix-web-module';
> 
> export const createNewContact = webMethod(Permissions.Anyone, async (contactInfo) => {
> try {
> const elevatedCreateContact = elevate(contacts.createContact);
> const newContact = await elevatedCreateContact(contactInfo);
> return newContact;
> } catch (error) {
> console.error('Error creating contact:', error);
> throw new Error('Failed to create contact.');
> }
> });
> 
> ```
> 
> ```javascript
> // Page code
> import { createNewContact } from 'backend/contacts.jsw'; 
> $w.onReady(function () {
> $w('#submitButton').onClick(async () => {
> const firstName = $w('#input7').value;
> const lastName = $w('#input16').value;  
> const email = $w('#input8').value;   
> 
> const contactInfo = {
> name: {
> first: firstName,
> last: lastName
> },
> emails: [{
> email: email
> }]
> };
> createNewContact(contactInfo);
> });
> });
> 
> ```
> 
> _Approach 3)_ GPT’s suggests only frontend
> 
> ```javascript
> import { contacts } from 'wix-crm';
> import { session } from 'wix-storage';
> $w.onReady(function () {
> $w('#submitButton').onClick(() => createContact());
> });
> async function createContact() {
> const name = $w('#input7').value;
> const email = $w('#input8').value;
> try {
> const contactInfo = {
> name: { first: name },
> emails: [{ email }]
> };
> const newContact = await contacts.appendOrCreateContact(contactInfo);
> session.setItem("createdContactId", newContact.contactId);
> } catch (error) {
> console.error("Error creating contact:", error);
> }
> }
> 
> ```

Many thanks!

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [October 13, 2025, 1:08pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/2 "2025-10-13T13:08:45Z")

</div>

> [@Gideon\_Skarzgard](#):
>
> Created contacts should appear on the Dash in _Customers & Leads \> Contacts_ right?

Correct 🙂

* * *

I noticed the second example suggested `contacts.jsw`, however .jsw is deprecated, and the code within the suggestion is for a `.web.js` file (which is what we encourage using).

* * *

Here’s some sample code that works:

Frontend:

```javascript
import { createNewContact } from "backend/contacts.web.js";

$w.onReady(function () {
    $w('#submitButton').onClick(async () => {
        const firstName = $w('#firstName').value;
        const lastName = $w('#lastName').value;
        const email = $w('#email').value;

        const contactInfo = {
            name: {
                first: firstName,
                last: lastName
            },
            emails: {
                items: [{
                    email: email
                }]
            }
        };
        createNewContact(contactInfo);
    });
});

```

Backend:

```javascript
import { contacts } from "@wix/crm";
import { auth } from "@wix/essentials";
import { webMethod, Permissions } from 'wix-web-module';

export const createNewContact = webMethod(Permissions.Anyone, async (contactInfo) => {
    try {
        const elevatedCreateContact = auth.elevate(contacts.createContact);
        const newContact = await elevatedCreateContact(contactInfo);
        return newContact;
    } catch (error) {
        console.error('Error creating contact:', error);
        throw new Error('Failed to create contact.');
    }
});

```

Don’t forget to install the SDKs for the backend 🙂

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 13, 2025, 3:47pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/3 "2025-10-13T15:47:53Z")

</div>

Thanks Noah. I tried this, had nothing & spent a while debugging with GPT, no related errors are even showing. I feel completely clueless😓

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [October 13, 2025, 3:50pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/4 "2025-10-13T15:50:12Z")

</div>

Can you share a link to the site?

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [October 13, 2025, 4:21pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/5 "2025-10-13T16:21:17Z")

</div>

Hi, @Gideon_Skarzgard !!

Just to confirm, have you installed the SDK as Noah mentioned? I think he probably meant that you need to search for and install `"@wix/crm"` and `"@wix/essentials"` via npm. 😇

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 13, 2025, 10:06pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/6 "2025-10-13T22:06:41Z")

</div>

Heyy @onemoretime & @noahlovell , I found my error; a rookie mistake! Your related code was correct! even some older attempts. I just had the same button.onClick also stated earlier in the code so they were clashing. Thanks to your replies, I tested with cleaner slates & now learnt to remember that!

After this fundamental code was successful, I’ve been trying my main requirement further, but stuck.

**I’m trying to** append a text input to a custom field of a contact. This is to accumulate some requests/info from users.

This part’s been daunting. Though I understand the code better now, I’m uncertain abt some pieces & their placing.. when & where some variables should be defined & called. My latest attempt is below (modified out of code from [SDK AI in dev docs](https://dev.wix.com/docs/sdk/)). I’d appreciate your tips🙏

```javascript
//**unsure which of these should go to the backend file
import { contacts } from '@wix/crm';
import { auth } from '@wix/essentials'; 
export async function appendToCustomField(contactId, customFieldKey, valueToAppend) {
  try {
    // Step 1: Retrieve the contact to get its current custom field value & revision
    // Elevate permissions if this function is called from frontend or needs elevated access
    const elevatedGetContact = auth.elevate(contacts.getContact);
    const contact = await elevatedGetContact(contactId);
    const currentRevision = contact.revision;
    const currentExtendedFields = contact.info.extendedFields?.items || {};

    // Step 2: Modify the custom field value
    let existingValue = currentExtendedFields[customFieldKey] || "";
    let newValue;
    valueToAppend = $w('#input16').value;
    newValue = existingValue + valueToAppend;
//**I tried replacing all [customFieldKey] with ["itsFieldName"]

    const updatedExtendedFields = {
      ...currentExtendedFields, //**I wonder if these dots are correct
      [customFieldKey]: newValue
    };
    // Step 3: Update the contact with the modified custom field
    const updatedContactInfo = {
      extendedFields: {
        items: updatedExtendedFields
      }
    };
    const elevatedUpdateContact = auth.elevate(contacts.updateContact);
    const updatedContact = await elevatedUpdateContact(contactId, updatedContactInfo, currentRevision);
    console.log('Appended to custom field:', updatedContact);
    return updatedContact;
  } catch (error) {
    console.error('Error appending to custom field:', error);
    throw error;
  }
}

```

```javascript
//the button part
$w.onReady(async function () {
//**I have working code getting the memberID. using getMember(). But unsure how to apply this
  $w("#submitButton").onClick(async () => {
    await appendToCustomField();
  });
}); 

```

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [October 14, 2025, 12:39am UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/7 "2025-10-14T00:39:29Z")

</div>

Good morning. 😗 For now, since the $w selector can’t be used in the backend, I think you’ll need to modify the code so that values are passed from the frontend to the backend through function arguments. 😇

```javascript
valueToAppend = $w('#input16').value;

```

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 14, 2025, 10:59am UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/8 "2025-10-14T10:59:29Z")

</div>

Thanks:) Based on your tips, I split the code to the front & backends & tried several iterations. Still nothing

```javascript
//backend code
import { contacts } from '@wix/crm';
import { auth } from '@wix/essentials'; // Required for elevated permissions if needed
export async function updateContactCustomField(contactId, customFieldKey, newCustomFieldValue) {
  try {
    // 1. Retrieve the contact to get its current revision
    const elevatedGetContact = auth.elevate(contacts.getContact); // Use elevate if necessary
    const contact = await elevatedGetContact(contactId);
    const revisionNumber = contact.revision;

    // 2. Prepare the update payload for the custom field
    const updatedContactInfo = {
      extendedFields: {
        items: {
          [customFieldKey]: newCustomFieldValue // Use bracket notation for dynamic key
        }
      }
    };

    // 3. Update the contact
    const elevatedUpdateContact = auth.elevate(contacts.updateContact); // Use elevate if necessary
    const updatedContact = await elevatedUpdateContact(contactId, updatedContactInfo, revisionNumber);
    console.log('Successfully updated contact custom field:', updatedContact);
    return updatedContact;
  } catch (error) {
    console.error('Error updating contact custom field:', error);
    throw error;
  }
}

```

```javascript
//page code
import { updateContactCustomField } from 'backend/contacts.web.js'; 
$w.onReady(function () {
  $w('#submitButton').onClick(async () => {
    const contactId = "237ab08c-58ea-4f06-b002-5b8484fd9f34"; // actual contact ID (UUID)
    const customFieldKey = "custom.infoRequests"; // Replace with your custom field key
    const newCustomFieldValue = $w('#input16').value; // Get value from your text input

    if (newCustomFieldValue) {
      try {
        const result = await updateContactCustomField(contactId, customFieldKey, newCustomFieldValue);
        console.log("Custom field updated successfully:", result);
      } catch (error) {
        console.error("Failed to update custom field:", error);
      }
    } else {
      console.warn("Text input is empty. Please enter a value.");
    }
  });
});

```

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [October 14, 2025, 2:01pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/9 "2025-10-14T14:01:49Z")

</div>

Have you already checked the logs in detail to determine exactly how far the process has succeeded? 🙃

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 14, 2025, 3:18pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/10 "2025-10-14T15:18:23Z")

</div>

This is the one console error I got, which I’m not knowledgeable enough to interpret, but it seems the backend function hasn’t worked even at a basic level. If this doesn’t help find the issue, pls let me know how I can make it easier for you

 ![Screenshot 2025-10-14 203621](https://us1.discourse-cdn.com/wix/original/3X/e/b/eb7cc266873d8e90076b06550d71bed53cc230b4.png)

GPT just says I should move this to a .jsw file…

 ![image](https://us1.discourse-cdn.com/wix/original/3X/5/3/53535cb54383425e3b6fcc2590f29423d6087da5.png)

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [October 14, 2025, 3:32pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/11 "2025-10-14T15:32:32Z")

</div>

Yeah, that’s a very simple mistake. 😙 The issue is that the backend function `updateContactCustomField` is still written in the old `.jsw` format, even though it’s being imported on the frontend as a `.web.js` module. This is a very common mistake. In other words, you can either rewrite the backend code using the `.web.js` format or simply import it as a `.jsw` file on the frontend, and it should work fine. Personally, I recommend updating it to the `.web.js` format for better consistency going forward. I was watching a soccer match earlier and got a bit too excited — to the point that I wasn’t feeling well — so I didn’t notice it at first. But as soon as I saw the error message you sent, it immediately clicked. It’s a very common error message. For now, go ahead and fix that part first. 😇

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 14, 2025, 6:54pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/12 "2025-10-14T18:54:47Z")

</div>

I’ve made significant progress thanks to you. After moving to a .jsw file it then logged a specific error; that the custom field wasn’t found. I then recreated a field named with only simple letters & it worked, **it can now _replace_ the field value**.  
I’ve been trying the appending part & now stuck here. My field is a text type

```javascript
    // 2️⃣ Get the current field value (if it exists)
    const currentValue = contact.info?.extendedFields?.[customFieldKey];
    // 3️⃣ Determine how to append based on the existing type
    let updatedValue;
    if (Array.isArray(currentValue)) {
      // Append new value to array
      updatedValue = [...currentValue, newCustomFieldValue];
    } else if (typeof currentValue === 'string') {
      // Append to string (comma-separated)
      updatedValue = currentValue
        ? `${currentValue}, ${newCustomFieldValue}`
        : newCustomFieldValue;
    } else if (currentValue) {
      // If it exists but is neither array nor string, wrap both in an array
      updatedValue = [currentValue, newCustomFieldValue];
    } else {
      // No existing value — just set it
      updatedValue = newCustomFieldValue;
    }

```

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [October 14, 2025, 7:18pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/13 "2025-10-14T19:18:29Z")

</div>

ChatGPT is largely basing it’s knowledge on older documentation/examples.

I’d highly recommend keeping it working with Web Methods since `.jsw` files are deprecated within the Wix ecosystem.

Web Methods aren’t simply exported functions as in the code shared. Here’s the documentation - [webMethod()](https://dev.wix.com/docs/sdk/core-modules/web-methods/web-method) - and the code I shared earlier also wraps in Web Method as required to work within a `.web.js` file and make it accessible from the frontend

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 14, 2025, 8:01pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/14 "2025-10-14T20:01:12Z")

</div>

Thank you! Will check it out

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [October 15, 2025, 2:26am UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/15 "2025-10-15T02:26:15Z")

</div>

Are you saying that even though the field is defined as a text type, it could still end up containing an array? 🙃

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 15, 2025, 10:14am UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/16 "2025-10-15T10:14:12Z")

</div>

I think not, but maintained uncertainty so someone that knows can inform me (whether text type here absolutely means type string, & even if so whether some syntax can make it act like other types). Anyway this was AI’s code that just gave many options. I’m most concerned with type text (as the only other types available in for custom field types are number, date & url)

To simplify I tried all the following variations that don’t give red underlines. But they either completely replaces or gives ‘undefined+ “the new value”’.

```javascript
let updatedValue = currentValue + newCustomFieldValue;

```

```javascript
let updatedValue = currentValue
  ? `${currentValue}, ${newCustomFieldValue}`
  : newCustomFieldValue;

```

```javascript
let updatedValue = `${currentValue}, ${newCustomFieldValue}`;

```

How can I properly append?

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 16, 2025, 10:40am UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/17 "2025-10-16T10:40:42Z")

</div>

Hi:), a lot was solved thanks to you but I’m stuck at this key part. If you could give some tips on [**this part**](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/16) I’d be grateful

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [October 17, 2025, 3:41pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/18 "2025-10-17T15:41:30Z")

</div>

To be honest, it would really help if you could clearly state once again exactly which contact field you’re ultimately trying to update. That would make the situation easier to understand and help others on the forum assist you more effectively. I haven’t personally used this API myself, so I can’t claim to know the exact answer just from reading the reference, and I’m a bit confused as well.

However, whenever things start to get confusing, the best approach is always the same: go back to basics, think simply, and verify each small step one by one. 😇

I’m not entirely sure which value you want to update, but are you trying to update a custom field you created inside `extendedFields`? Also, I believe what you’re attempting to do is almost identical to the example shown in the reference (only the `updatedContactInfo` part is different), so I think you can basically use that as it is. It’s already written in the `.web.js` format. 😙

```javascript

/ *************************************
 * Backend code - contacts.web.js/ts *
 ************************************ /

import { Permissions, webMethod } from "@wix/web-methods";
import { contacts } from "@wix/crm";
import { auth } from "@wix/essentials";

export const overwriteContactInfo = webMethod(
  Permissions.Anyone,
  async (contactId, updatedContactInfo) => {
    try {
      // Retrieve the contact
      const elevateGetContact = auth.elevate(contacts.getContact);
      const contact = await elevateGetContact(contactId);
      // Extract revision number
      const revisionNumber = contact.revision;
      // Update the contact
      const elevateUpdateContact = auth.elevate(contacts.updateContact);
      const updatedContact = await elevateUpdateContact(
        contactId,
        updatedContactInfo,
        revisionNumber,
      );

      return updatedContact;
    } catch (error) {
      console.log(error);
      // Handle the error
    }
  },
);

/ *************
 * Page code *
 ************* /

import { overwriteContactInfo } from "backend/contacts.web";

$w.onReady(async function () {
  const contactId = "2712ae1d-3f64-46c2-ac3a-94a6c2e29847";
  const updatedContactInfo = {
    name: {
      first: "John",
      last: "Mitchell",
    },
  };
  async function updateContactName() {
    try {
      const updatedContact = await overwriteContactInfo(
        contactId,
        updatedContactInfo,
      );

      return updatedContact;
    } catch (error) {
      console.log(error);
      // Handle the error
    }
  }
  const result = await updateContactName();
  const first = result.contact.info.name.first;
  const last = result.contact.info.name.last;
  console.log(`Updated contact name: ${first} ${last}`);
});

```

> **[Update Contact | API Reference](https://dev.wix.com/docs/api-reference/crm/members-contacts/contacts/contacts/contact-v4/update-contact?apiView=SDK)**
>
> Updates a contact. Each time the contact is updated, revision increments by 1. The existing revision must be included when updating the contact. This ensures you're working with the latest contact information, and it prevents unintended overwrites.

Well, with this code, it seems like you could easily overwrite the predefined fields in the API (like `name` or `emails`). 🙂  
In your case, I understand that you have your own custom field values and are trying to handle them using `extendedFields`, right? 🙃

If that’s correct, you might need to experiment a bit to confirm how it behaves.  
But my impression is that you could probably create the `updatedContactInfo` object in the same way as when updating fields like `name` or `emails`, and then simply pass it as an argument.  
After that, the `updateContact` API should handle the rest automatically.

Though I haven’t tried it myself, so I can’t say for sure. 😇

---

<div class="post-metadata">

**Author:** ![Gideon\_Skarzgard](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gideon_skarzgard/32/87597_2.png) [@Gideon\_Skarzgard](https://forum.wixstudio.com/u/Gideon_Skarzgard)\
**Post date:** [October 18, 2025, 12:19pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/19 "2025-10-18T12:19:19Z")

</div>

> [@onemoretime](#):
>
> you have your own custom field values and are trying to handle them using `extendedFields`, right?

yes

So, all the steps worked except just the appending part, which I kept manipulating, and I GOT IT!  
For your guidance @onemoretime ありがとうございます!

The full the working code for anyone needing it is at the bottom  
(Bear in mind this may not be most reliable considering the backend is in a .jsw as pointed out [above](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/13) by noah)

```javascript
//backend- contacts.jsw
import { contacts } from '@wix/crm';
import { auth } from '@wix/essentials'; // Required for elevated permissions if needed

export async function updateContactCustomField(contactId, customFieldKey, newCustomFieldValue) {
  try {
    // 1. Retrieve the contact to get its current revision
    const elevatedGetContact = auth.elevate(contacts.getContact); // Use elevate if necessary
    const contact = await elevatedGetContact(contactId);
    const revisionNumber = contact.revision;

    // 2️⃣ Get the current field value (if it exists)
    const currentExtendedFields = contact.info.extendedFields?.items || {};

    // Step 2: Modify the custom field value
    let updatedValue;
    let existingValue = currentExtendedFields[customFieldKey] || "";
    updatedValue = existingValue + newCustomFieldValue;

    // 4️⃣ Prepare the update payload
    const updatedContactInfo = {
      extendedFields: {
        items: {
          [customFieldKey]: updatedValue
        }
      }
    };

    // 5️⃣ Update the contact with the new value
    const elevatedUpdateContact = auth.elevate(contacts.updateContact);
    const updatedContact = await elevatedUpdateContact(contactId, updatedContactInfo, revisionNumber); 

    console.log('Successfully updated contact custom field:', updatedContact);
    return updatedContact;
  } catch (error) {
    console.error('Error updating contact custom field:', error);
    throw error;
  }
}

```

```javascript
//frontend
import { updateContactCustomField } from 'backend/contacts.jsw'; // Adjust path as needed
$w.onReady(function () {
  $w('#submitButton').onClick(async () => {
    const contactId = "237ab08c-58ea-4f06-b002-5b8484fd9f34"; // Replace with actual contact ID
    const customFieldKey = "custom.fieldname"; // Replace fieldname with yours
    const newCustomFieldValue = $w('#input16').value; // Get value from your text input

    if (newCustomFieldValue) {
      try {
        const result = await updateContactCustomField(contactId, customFieldKey, newCustomFieldValue);
        console.log("Custom field updated successfully:", result);
      } catch (error) {
        console.error("Failed to update custom field:", error);
      }
    } else {
      console.warn("Text input is empty. Please enter a value.");
    }
  });
});

```

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/system/32/86885_2.png) [@system](https://forum.wixstudio.com/u/system)\
**Post date:** [November 17, 2025, 12:20pm UTC](https://forum.wixstudio.com/t/create-or-append-a-contact-with-code/74202/20 "2025-11-17T12:20:05Z")

</div>

Closed on November 17, 2025, 12:20pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
