Triggered Email Button to set collection value

Hi,

I’m really stuck on this issue.
I have created a a triggered email that gets sent when a sensor device is “Activated”. I have a field in my collection called ‘email’ that is True when I want to send emails to the user for that device.

I would like the email to have a button they can click which will set the collection field ‘email’ to false so they wont receive more emails until they set it back to true. Using a button on one of my pages.

Basically I want a button on a triggered email that is able to call a function in the back end to update a collection field.

Thanks,
Andrew Vermeeren

It’s not possible. Instead, You can send a link.

You need to create a dynamic page on your website that will take incoming requests and update the email status.

You could have something like www.mydomain.com/email-activity/${user-code}/activate and www.mydomain.com/email-activity/${user-code}/ deactivate

you can then a backend function manageEmailSubscription that would work like that

export async function manageEmailSubscription(userCode, isActive) {
   const item = await wixData.query(EmailCollection).eq(userCode, isActive).find().then(result => result.items[0])
   
   item.isActive = isActive
   
   return wixData.update(EmailCollection, item);
}

then make it so your button redirect the user to that page

(you could also use userId but this require a member area + member to be logged in)

As in send a link to the webpage where they can click a button to set the email field to false?

@andrew71059 No. See Kentin post below.

I don’t think you need dynamic pages. Just put URL parameters on the link and trigger the code that way.

But either way, how are you preventing users from activating links that don’t belong to them? ie if the email containing the link is forwarded, someone other than the intended recipient can update that users data.