Nylas JS SDK: Solving "you cannot update the status of participants" error when rescheduling an event

This is a really quick post to help anyone else who has run up against an error while using the Nylas Node.JS SDK to reschedule an event.

Context

To edit an event using the SDK, you get the event, make changes to the properties and then call save() like this:

   async rescheduleEvent(start: DateTime, end: DateTime, event_id: string) {
        const event = await this.nylas.events.find(event_id);
        event.when = {
            start_time: start.toSeconds(),
            end_time: end.toSeconds(),
        };
        return event.save({ notify_participants: true });
    }

Problem

When you attempt to save this event, you receive an error that states you cannot update the status of participants. As is often the case, the error message holds the key to the solution.

If you inspect the event object returned by Nylas, you'll notice that the Participant model in the participants array contains a status field. This field indicates the RSVP status of that participant. When you reschedule an event, you cannot set everyone's RSVP, it has to be reset so they can RSVP based on the time change. Hence the you cannot update the status of participants which seems much clearer in retrospect.

Solution

The simple fix that I found was to map the participants array to just the name and email before calling save().

    async rescheduleEvent(start: DateTime, end: DateTime, event_id: string) {
        const event = await this.nylas.events.find(event_id);
        event.when = {
            start_time: start.toSeconds(),
            end_time: end.toSeconds(),
        };

       //start:solution
       event.participants = event.participants.map((participant) => {
            return {
                name: participant.name,
                email: participant.email
            };
        });
        //end:solution

        return event.save({ notify_participants: true });
    }

Now while the fix is simple in execution, but I think this issue should be handled by their API or SDK, rather than falling on the app developer.

Conclusion

I hope this helps anyone that is using the Nylas API and SDK to manage bookings. If you haven't heard of Nylas and are still here, you should definitely check them out and see if they can help you on your next project.

If you found this quick tip helpful, let me know in the comments or hit me up on Twitter @jmzaborowski