Been trying to send triggered email to contacts via code
It works successfully if one initially puts their details in. But if one tries to enter other details right after the first successful submission, you get a 401 error.
(even if one refreshes the page after the first success, it gives the same error)
Code below
import wixCRM from 'wix-crm';
$w.onReady(function () {
$w("#button1").onClick( () => {
wixCRM.createContact( {
"emails": [$w('#input1').value]
} )
.then( (contactId) => {
wixCRM.emailContact('S4JWci4', contactId, {
variables: {
"name": $w('#input2').value
}
})
.then(() => {
console.log("email sent");
})
.catch((err) => {
console.log("email failed");
console.log(err);
// handle the error if the email wasn't sent
});
} );
} );
401 error log
root":{
“insertId”:“…79Pi5brch84tB_MCnKq92Y”
“timestamp”:“2020-07-10T07:24:08.420Z”
“severity”:“INFO”
“labels”:{“siteUrl”:“https://jaosh8.wixsite.com/mysite-6”
“namespace”:“Corvid”
“tenantId”:“2115dab8-f6ac-473a-bcd8-41484b163603”
“viewMode”:“Site”
“revision”:“27”
}
“operation”:{“id”:“…7B0vXlny0BO8slDIZi.6yX”
“producer”:“/blank”
“first”:false
“last”:false
}
“sourceLocation”:{}
“jsonPayload”:{“message”:“contactId does not match current session contact (401)”
}
“receiveTimestamp”:“2020-07-10T07:24:09.513Z”
}