I have a contact form in a lightbox in which I’ve implemented my own code to send a triggered email when the “submit” button is clicked. The way it should work is it creates a contact with the email selected in the dropdown, and sends it to that contact with the field values as text in the email. (Essentially a rudimentary support ticket system). When I click submit (in preview or on the live site), I consistently get a bad request error, and I don’t have enough information to keep troubleshooting (though I’ve tried for weeks now).
I’d like to fix this bug, but additionally, if anyone knows a better way to do this, please do let me know!
Thanks
(Image is the error in the console, first text is the contents of the referenced file in the error; https://editor.wix.com/_api/wix-contacts-webapp/v3/contacts), final text is the referenced block of code.
{“message”:“missing_context, details: {"fields":"MSID / (appDefId, instanceId)","apps":"null","entities":"{\"identities\":[{\"person\":{\"id\":\"c46858dc-7237-48a4-8f22-8c5beac5cf95\"}}]}"}”,“details”:{“entities”:“{"identities":[{"person":{"id":"c46858dc-7237-48a4-8f22-8c5beac5cf95"}}]}”,“error”:“missing_context”,“fields”:“MSID / (appDefId, instanceId)”,“category”:“api_error”,“apps”:“null”}}
export function submit_click(event) {
if (fields_valid()) {
let sendaddress = $w(“#contactcategory”).value ? String($w(“#contactcategory”).value) !== “null” : “info@mysite.org”; // Replaced my site name with “mysite”
let cname = $w(“#contactname”).value;
let cemail = $w(“#contactemail”).value;
let ccategory = $w(“#contactcategory”).options[$w(“#contactcategory”).selectedIndex].label;
let cphone = $w(“#contactphone”).value ? $w(“#contactphone”).value : “”;
let cmessage = $w(“#contactmessage”).value;
let vars = {
name: cname,
email: cemail,
category: ccategory,
message: cmessage,
// I've tried changing the "respond" param to a simple string. Didn't fix it.
respond: "<a href='mailto:" + cemail + "'>Click Here to Respond</a>"
}
if (cphone !== **null** && cphone !== "") {
vars["phone"] = cphone
}
wixCRM.createContact({
// I've tried adding dummy firstName and lastName params. No luck.
"emails": [sendaddress]
})
.then((contactID) => {
wixCRM.emailContact("contact", contactID, {variables: vars})})
.then(() => {
console.log("Triggered email sent");
})
. catch ((err) => {
console.log(err);
});
}
I’m starting to suspect this is a Wix bug, but I emailed Wix support and they told me to post here, so here I am.
Thanks in advance!