Update label contact

Hi everyone,
I need to simply update the lable of a contact already registered in wix.

I found this resource in the forum
https://www.wix.com/corvid/forum/community-discussion/updateuserinfo-is-not-updating?origin=member_posts_page

I found these two references in the API
https://www.wix.com/corvid/reference/wix-crm-backend.html#updateContact
https://www.wix.com/corvid/reference/wix-users-backend.html#updateUserFields

But I’m still a beginner and I don’t know how I should configure them for my purpose Could you please help me?

Thanks!!!

Hello,

Please start from reading the following articles that will help you start:

About Corvid by Wix - what Corvid is and what features it has.
Getting Started with Corvid by Wix - step-by-step tutorial on how to start using Corvid.
Onboarding to Corvid by Wix - introduction to Corvid with short tutorials.

As you will need to use wix-users-backend in order to implement this, please read the article below:
Corvid Web Modules: Calling Server-Side Code from the Front-End

Then, you can use a code snippet directly from the API you mentioned and adjust it to your needs. Here you can find its syntax.

Good luck!

Thanks for your answer, but I’m not quite so inexperienced.
I have already created several sites with the CORIVID code, however reading often information here I see that there are a lot of people much more expert than me and therefore I consider myself a beginner.

Can you help me on the code regarding the specific problem I asked?

How do I update the label of an existing contact?

Thank You!

So basically you are wanting somebody to write the needed code for you :wink:

As you have already stated that you need to be using the updateContact function through the backend for updating Contacts labels.
https://www.wix.com/corvid/reference/wix-crm-backend.html#updateContact

So you just need to write your code in a backend file for this and there is a clear example in the Wix API reference for it.

Then just make sure that you import the function from the backend on your page along with your other imports and call this function in your code too.

You can read how to do this on the page that Anastasiia linked for you in her reply. Corvid Web Modules: Calling Server-Side Code from the Front-End

Examples
Update an existing contact
This example contains a backend function that updates a contact.

import wixCrm from 'wix-crm-backend';

export function myBackendFunction(contactId, firstName, lastName, email, phone) {
  wixCrm.updateContact(contactId, {
      "firstName": firstName,
      "lastName": lastName,
      "emails": [email],
      "phones": [phone]
  } )
    .then( () => {
      // contact has been updated
    } )
    .catch( (err) => {
      // there was an error updating the contact
    } );
}

You can see from this example how to add a field that is an array and as you are wanting to update the label, then you just need to add it to suit.

As shown in the Contact Info section.

ContactInfo
An object that contains information about a site contact.

Syntax

type ContactInfo = {
firstName: string
lastName: string
picture: string
emails: Array
loginEmail: string
phones: Array
labels: Array
language: string

LABELS - Array
List of contact’s labels. Labels are used to organize contacts. When setting the labels property, you can only list labels that already exist in your site’s Contacts List.

Just note as well that the updateUserFields is for site members which uses the Wix Users API and not for Site Contacts that uses the Wix CRM API.
https://www.wix.com/corvid/reference/wix-users-backend.html#updateUserFields

So it is basically the same way as above, however you are using a different API for it, so do not get them mixed up.

Examples
Update a user

import wixUsersBackend from 'wix-users-backend';

export function updateUserFields(userId, firstName, lastName, email, phone) {
  wixUsersBackend.updateUserFields(userId, {
      "firstName": firstName,
      "lastName": lastName,
      "emails": [email],
      "phones": [phone]
  } )
    .then( () => {
      // contact has been updated
    } )
    .catch( (err) => {
      // there was an error updating the contact
    } );
}

Also, note that as they are users you have more info that you can pass through the user info section compared to the contact info with Contacts.
https://www.wix.com/corvid/reference/wix-users-backend.html#UserInfo

Hi GOS, how are you? everything good?
In practice, I seem to have done what you tell me, but surely there is an error because it still doesn’t work. Can you tell me what I’m doing wrong at this point?

file contact.jsw

import wixCrm from ‘wix-crm-backend’;
export function updateContact(contactId) {
wixCrm.updateContact(contactId, {
“labels”: [“Contatto”]
} )
.then( () => {
// contact has been updated
} )
. catch ( (err) => {
// there was an error updating the contact
} );
}

file front-end in my page

import { updateContact } from “backend/contact.jsw”;
import wixUsers from ‘wix-users’;
let user = wixUsers.currentUser;
let customId = user.id;
$w.onReady( function () {
});
export function buttonTest_click(event) {
$w(“#test”).value = customId;
updateContact(customId)
}

Description

The updateContact() function returns a Promise that resolves when the contact with the specified ID has been updated.

Only the properties passed in the ContactInfo object will be updated. All other properties will remain the same.

export function myBackendFunction(contactId, firstName, lastName, email, phone) {

Your code.

export function updateContact(contactId) {

Thanks as always GOS! I have to offer you a glass of good whiskey!