wixCRM.createContact does not create nor error

Hello and thank you.
This question comes out of an existing thread where I posted a different question - which has not yet been resolved.

(the original post: https://www.wix.com/corvid/forum/community-discussion/how-can-i-get-a-contact-id)

CODE IS BELOW.
Trying to create a NEW contact.
It is NOT creating the contact, nor is it generating an error.
Ultimately… I could care less about the contact. ALL I NEED is the contactID

Any thoughts?

import wixCrm from 'wix-crm';

export function myContact() {

 // it's hitting this and displaying this msg accurately...
    console.log("RECREATE CONTACT");

let firstName = 'myFirstname'
let lastName = 'myLastname'
let email = 'register@pulakico.com'

let contactInfo = {

 "firstName": firstName,
 "lastName": lastName,
 "emails": email
};

// it's hitting this and displaying the contactINFO accurately...
    console.log("tvx NEW CONTACT=");
    console.log(contactInfo);

wixCrm.createContact(contactInfo) 
.then( (contactId) => {

 //  never hits this code, no contact created
     console.log("tvx contactID=");
     console.log(contactId);
})    
.catch( (err) => {

 //  never hits this code
      console.log(err);
});
}

// it's hitting subsequent code successfully, and executing fine.

P lease observe the community guidelines and refrain from multiple posts on the same topic or question.

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

Got it. Thanks! I ripped this question from the original post because it was really a separate question, unrelated to the original.

I thought mentioning the orig. with a link would be enough, but I won’t do that again. : -)

SOLUTION via Wix Support Person, Yisrael,:

The EMAIL in the contact info object needed to be in an array:
let email = [ ‘register@pulakico.com’]

Thank you, Yisrael.

Yisrael, I’ve been round and round on this issue.

wixCRM.createContact FAILS and I can’t get the contactId to send an email. Here’s my code:

wixCRM . createContact ({
“firstName” : $w ( ‘#input2’ ). value ,
“lastName” : $w ( ‘#input3’ ). value ,
“phones” : [ $w ( ‘#input5’ ). value ],
“emails” : [ $w ( “#input4” ). value ]
})
. then (( contactId ) => {
console . log ( “Contact Created contactId=” + contactId );
triggeredEmails . emailContact ( “Sosgvzd” , contactId , {

“variables” : {
“InviteesName” : InviteeName ,
“TeamName” : $w ( “#input1” ). value
}
})
})
. catch ( ( err ) => {

  console . log ( err ); 
}); 

.then never happens
.catch never happens
and I’ve tried the other form by creating the contact structure first, and it makes no difference.

Why can’t wixCRM be fixed to create a contact OR return the contactId if it already exists?

RIGHT NOW, HOW do I get this to work? Do I have to check for an existing contact myself?

The problem is EVEN A NEW CONTACT seems to fail. I can’t get createContact to do anything.

Where are you calling this code? Are you sure that the values being used are valid? What error message are you getting? Try using some console.log() statements to help determine what’s going on.

Note that createContact() has been deprecated (although it still works). You should be using appendOrCreateContact() .

Hello Yisrael,

I got the createContact() working. My code is inside onReady. I save the data using

$w('#dataset1').setFieldValues( {
    "title": TeamName, 
    "firstname": $w("#input2").value,
    "lastname": $w("#input3").value,
    "email": $w("#input4").value,
    "cell": $w("#input5").value
});
  $w('#dataset1').save();

then the onAfterSave event, I got working, to create a contact then I try to use the _id to send a Triggered Email. This fails with FAILED TO FETCH. Did I loose my Triggered Email access somehow? I bought more emails so I have 7, but it’s not working. Here’s my code. which seems to go all the way to

wixCRM.emailContact(‘Sosgvzd’, contactId, { //SrhtD9P // Sosgvzd
or
triggeredEmails.emailContact(‘Sosgvzd’, contactId, { //SrhtD9P // Sosgvzd

aren’t both the same?

Here’s my code:

//import wixData from 'wix-data';   // don't use this, no onAfterSave callback
import wixLocation from 'wix-location';
import wixCRM from 'wix-crm';             // using this now for triggered email
import { triggeredEmails } from 'wix-crm';  // tried this not different
import {memory} from 'wix-storage';
import {fetch} from 'wix-fetch'
//import {sendEmail, sendEmailWithRecipient} from 'backend/email';


$w.onReady(function () {
 let TeamId = memory.getItem("TeamId");
 let TeamName = memory.getItem("TeamName");
 $w("#text63").text = TeamName;

$w('#dataset1').onAfterSave( () => {
  console.log("onReady dataset1.onAfterSave()");
  let TeamName = memory.getItem("TeamName"); 
  let InviteeName = $w("#input2").value + " " + $w("#input3").value;;
    let firstName = $w('#input2').value;
    let lastName = $w('#input3').value;
    let email = $w('#input4').value;
    let phone = $w('#input5').value;
    console.log("SENDING EMAIL"+" mailto:"+email+" TeamName-"+TeamName+" phone="+phone+" InviteeName="+InviteeName);

    let contactInfo = {
      "firstName": firstName,
      "lastName": lastName,
      "emails": [email],
      "phones": [phone],
    };
   console.log("contactInfo set "+contactInfo)
  
      wixCRM.createContact(contactInfo)
      .then( (contactId) => {
            console.log("Contact Created contactId="+contactId);  // THIS MESSAGE SHOWS CORRECTLY
          //triggeredEmails.emailContact('Sosgvzd', contactId, {   //SrhtD9P  // Sosgvzd
          wixCRM.emailContact('Sosgvzd', contactId, {  //SrhtD9P  // Sosgvzd
             
            "variables": {
              "InviteesName": InviteeName,  // these 2 variables are in the triggered email
              "TeamName": TeamName
              }
            })
            .then( () => {
            console.log("Triggered Email SENT");  // THIS MESSAGE NEVER SHOWS, I GET ERROR "FAILED TO FETCH"
            // FOLLOWING CODE IS EXECUTED ON SUCCESS OF EMAIL SEND, I CALL THIS PAGE FROM 2 PLACES, AND IT MUST RETURN ONE OF 2 PLACES BASED ON "from" in memory
       /*   if(memory.getItem("from") == "Create-Team"){
            wixLocation.to("/account/Create-a-Team-3");
            }else{
            wixLocation.to("/account/Edit-Team");
            } */
            }) 
         } )
        .catch( (err) =>{
            let errorMsg = err;
            console.log("TRIGGERED EMAIL ERROR-->",errorMsg);
          });
    }); // onAfterSave

    // button2 is the save and invite button
$w("#button2").onClick( (event) => {

  $w('#dataset1').setFieldValues( {
    "title": TeamName, 
    "firstname": $w("#input2").value,
    "lastname": $w("#input3").value,
    "email": $w("#input4").value,
    "cell": $w("#input5").value
});
  $w('#dataset1').save();

});   // BUTTON2 CLICK END

});  // ONREADY END



/*triggeredEmails.emailContact('Sosgvzd', emailadd, {
  variables: {
    TeamName: TeamName,
   //ProjectName: <enter-value-here>,
    InviteesName: InviteeName,
   // name: <enter-value-here>
  }
});*/

Yisrael, do I have a back end problem? I’m using wixCRM.emailContact or TriggeredEmails.emailContact

Why FAILED TO FETCH? Is it in the email definition somehow?

Do I need to do this?
Call this function findMember . In the example below we return an ID if one exists in the member Database for the give email, if not, an ID is created with wixCrm and returned.

import {findMember} from 'backend/members'function getID(eMail, firstName, lastName){return findMember(eMail).then((Id)=>{if (Id !== 0){
    console.log("existing member.");return Id
    }else {
    console.log("create new contact");return wixCrm.createContact( {"firstName": firstName, "lastName": lastName, "emails": [eMail]} )}})}
    

I’m not doing this, I just use wixCRM.createContact, if one exists I assume it overwrites it with any changes in the fields.