Welcome to the Forum 🙂
Yes, you are correct. For any data operation that should be done automatically & independent of the access point (API, forms, CSV import, etc.), you would use a triggered backend function.
For this case, a BEFORE trigger would work best. With a BEFORE trigger, you have direct access to the current record via the NEW keyword - like this:
NEW.(my_app.cid.last_seen) := EXTRACT(EPOCH FROM NOW());
If you trigger this function on your
cid relation ON INSERT/UPDATE EACH ROW, the
last_seen attribute would always be overwritten with the current time whenever a record is created or changed. Just make sure, that you use the placeholders inside the backend function.
For a not-so short tutorial on backend functions / triggers, here is a Youtube video.