Hello, I created I function that add label to contacts (members) but when function fired from live site it doesn’t work when I test it from backend with sample id and label it works I checked id and label is coming right from live website and there was no problem here is the backend and frontend code:
Backend
export function createLabelIfUndefined(userId, label) {
console.log(userId, label)
let contactId = userId;
let labelKeys = [
"custom." + label
];
console.log(labelKeys)
const options = {
suppressAuth: false
};
return contacts.labelContact(contactId, labelKeys, options)
.then((labeledContact) => {
console.log("TAMAMLANDI")
return labeledContact;
})
.catch((error) => {
console.error(error);
});
}
Frontend
import { createLabelIfUndefined } from 'backend/memberModules.jsw'
import wixUsers from 'wix-users';
let id = wixUsers.currentUser.id;
let label = "";
let endLabel = "";
$w.onReady(function () {
function toEnglishCharacters(x) {
x = x.replace(/ö/g, 'o');
x = x.replace(/ç/g, 'c');
x = x.replace(/ş/g, 's');
x = x.replace(/ı/g, 'i');
x = x.replace(/ğ/g, 'g');
x = x.replace(/ü/g, 'u');
x = x.replace(/Ö/g, 'o');
x = x.replace(/Ç/g, 'c');
x = x.replace(/Ş/g, 's');
x = x.replace(/I/g, 'i');
x = x.replace(/Ğ/g, 'g');
x = x.replace(/Ü/g, 'u');
let end = x.toLocaleLowerCase().split(' ').join('-');
endLabel = end;
return end;
}
$w("#label").onChange((event) => {
label = $w("#label").value;
toEnglishCharacters(label)
})
$w("#sendData").onClick((event) => {
createLabelIfUndefined(id, endLabel)
.then((data) => {
console.log("Label Added");
})
.catch((err) => {
console.log("Hata:", err)
})
})
})
Screenshots