As long as the user is not registered in your LOGIN-SYSTEM/CONTACTS he won’t have an ID. So the following is logical →
I’ve got this error the the google console : 109 Error: contactId does not match current session contact (401)
→ Customers submit a form without logging in (they’re not site members yet)
What could be possible?
Use an external email service (like SendGrid, Mailchimp Transactional, or EmailJS) via backend code, pulling the customer’s email address directly from the form submission.
Try Email-JS, should be simple. Sendgrid also a possible solution.
You grab the email of the user either directly from the input-field…
const customerEmail = $w(“#emailInput”).value; or from cms later.
Then you generate something similar like —>
// backend/sendEmail.jsw
import { fetch } from 'wix-fetch';
export function sendConfirmationEmail(to, subject, body) {
const apiKey = "YOUR_SENDGRID_API_KEY";
return fetch("https://api.sendgrid.com/v3/mail/send", {
method: "post",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
personalizations: [{ to: [{ email: to }] }],
from: { email: "your@email.com", name: "Your Restaurant" },
subject: subject,
content: [{ type: "text/plain", value: body }]
})
}).then(response => response.json());
}
…and …
import { sendConfirmationEmail } from 'backend/sendEmail';
$w.onReady(() => {
// assuming you validate the reservation here
const customerEmail = item.email; // retrieved from the collection
const subject = "Reservation Confirmed";
const message = `Hi ${item.name}, your reservation has been confirmed!`;
sendConfirmationEmail(customerEmail, subject, message)
.then(() => console.log("Email sent"))
.catch(err => console.error("Email failed", err));
});
Those are just examples, you will have to modify and to edit those, for example using the newer wix architecture for backend-coding…
webMethod( )
Defines a backend function that can be called from the frontend.
The webMethod()
function is a wrapper used to export functions from backend code that can be called from the frontend.
The permissions
parameter is used to define the permissions needed to call the function in frontend code. Import the Permissions
enum from the wix-web-module
module to define the permissions. The permission options are:
Permissions.Anyone
: Any site visitor can call the function.
Permissions.Admin
: Only site admins can call the function.
Permissions.SiteMember
: Only site members can call the function.
The cache
object, found in the options
parameter, allows you to cache or temporarily store the return value of web methods. Use the ttl
property to define the duration, in seconds, for which you want the return value to be cached. If the Time To Live (TTL) is not set, the default value is 604800
seconds, which is approximately 1 week.
Assign identifiers to caches using the tags
property of the cache
object. Tags enable you to specify cached return values that may require invalidation due to significant changes in your data. To invalidate web method caches, use the invalidateCache()
function from wix-cache-backend
. Once invalidated, the return value is re-cached the next time your backend function is called. Learn more about web method caching.
Important:
- The
tags
property is required for caching. Without tags, nothing is cached.
- The
invalidateCache()
method from wix-cache-backend is currently in developer preview.
Web methods must be defined in files with a .web.js
extension and so on and so on…