The wixCode page specifically says
Calling createContact() performs one of the following. (The contact information specified in the contactInfo parameter matches an existing contact if it contains an email address or phone number from an existing contact.)
-
If there is no matching existing contact, a new contact is created using the information specified using the contactInfo parameter.
-
If there is a matching existing contact, it is updated with the information specified using the contactInfo parameter. Any existing contact information that is not explicity overriden in the contactInfo parameter retains its existing value.
However when doing this i get
Uncaught (in promise) Error: server responded with 403 - {“message”:“permission_denied, details: {"Error":"A member with these communication details (Email / Phone) already exists"}”,“details”:{“error”:[“permission_denied”,“A member with these communication details (Email / Phone) already exists”],“category”:“api_error”}}
Yes wix… Yes i know that a contact exists with this email… im trying to update that contact via option #2 the way you told me to, to update a custom variable on contacts to make my life easier
Site members can change their Screen Names on my site and I want to add that to the contact as a custom screenName variable so i know who is messaging me through wixChat
What is the proper way to go about this or Does this just Not work
Editing of a contact works if the contact has not yet been approved
The option number 2 still doesn’t work… The contact isn’t updated in the contact list. Did you find a solution for this or this just simply doesn’t work? Btw: we are talking about contacts not “members” which is obviously something different
It does work, however Wix CRM will only work with Contacts that are in your Contacts list through your Wix Dashboard.
If those Contacts have since been registered for your site and are now classed as site members, then you can’t use Wix CRM to do this, you will need to use Wix Users.
What’s the difference between wix-crm and wix-users?
The CRM API contains functionality for working with your site’s contacts. The Users API contains functionality for working with users who are logged-in members. Note that all members are also contacts, but contacts are not necessarily members.
Note
You cannot use the createContact() function to update contact information for existing site members. You can use use it to update other site contacts.
Have a read of API references and all functions here, which includes the backend versions too.
https://www.wix.com/corvid/reference/wix-crm.html
https://www.wix.com/corvid/reference/wix-crm-backend.html
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users-backend.html
Especially when you have lines like this in createContact() info.
The passed ContactInfo object must contain at least one email address or phone number.
Also, note that if you use createContact() then you use Wix CRM. However, if you use updateContact(), then you are using Wix CRM Backend.
@givemeawhisky
Hello! firstly I would like to thank you for taking the time to answer… I can confirm however that the CRM Api doesn’t update any of the contacts stored in the Wix contact list. I am talking about contacts (not site members). And they are not listed as members, they are just contacts.
I Have a basic form with name, lastname and email. this is the code that I am using. The variables are connected to input fields, and everything runs with the button’s onclick .
export function signUpButton_click(event) {
let firstName = $w(“#inputName”).value,
let lastName = $w(“#inputLastName”).value,
let email = $w(“#inputEmail”).value
wixCRM.createContact( {
“firstName”: firstName,
“lastName”: lastName,
“emails”: [email]
} )
.then( (contactId) => {
console.log(“contact created”)
} );
}
As stated in the reference :
Calling createContact() performs one of the following. (The contact information specified in the contactInfo parameter matches an existing contact if it contains an email address or phone number from an existing contact.)
-
If there is no matching existing contact, a new contact is created using the information specified using the contactInfo parameter.
-
If there is a matching existing contact, it is updated with the information specified using the contactInfo parameter. Any existing contact information that is not explicity overriden in the contactInfo parameter retains its existing value.
Registering the contact for the first time works perfectly, however when the contact is already on the contact list (which would be the option #2 of the API) nothing happens, the contact stays the same. And even when I delete the contact from the contacts list, and repeat the registration using the form, It appears with the old name again… which is a very weird behaviour.
I thank you for your help and maybe you have an idea what is happening here… I also read some posts here in the forum of people having exactly the same problem.
Cheers
Fernando
@fernandust
You are basically just using this code.
import wixCRM from 'wix-crm';
// ...
let firstName = // get first name
let lastName = // get last name
let email = // get email address
let phone = // get phone number
wixCRM.createContact( {
"firstName": firstName,
"lastName": lastName,
"emails": [email],
"phones": [phone]
} )
.then( (contactId) => {
// contact created
} );
Try using this code instead.
import wixCRM from 'wix-crm';
// ...
let firstName = // get first name
let lastName = // get last name
let email = // get email address
let phone = // get phone number
let contactInfo = {
"firstName": firstName,
"lastName": lastName,
"emails": [email],
"phones": [phone],
//"customField1": "customValue1",
//"customField2": "customValue2"
};
wixCRM.createContact(contactInfo)
.then( (contactId) => {
// contact created
} );
// Take out "customField1 and customField2 lines if not using them.
@givemeawhisky that’s exactly the same code… The only difference is that the object
Contactinfo is created as a variable and passed to the function. My version has the object directly inside the function’s parameter. Which is the same. With this code contacts are created but very sadly not updated. Is anyone else experiencing this issue?