Source: https://cli.nylas.com/guides/generate-ics-file-cli

# Generate an ICS File from the Terminal

An.ics file is the universal calendar format — attach it to an email and any client will offer to add the event. You don't need a library to make one: read an event as JSON with the Nylas CLI and assemble a VCALENDAR block, which is plain text defined by RFC 5545. This guide builds a valid.ics from a real event, covers the fields that matter, and notes when you can skip the file entirely because the CLI already sends iCalendar invites.

Written by [Pouya Sanooei](https://cli.nylas.com/authors/pouya-sanooei) Software Engineer

Updated June 8, 2026

> **TL;DR:** Read an event as JSON with `nylas calendar events show --id EVENT_ID --json`, then wrap its fields in a `BEGIN:VCALENDAR` / `VEVENT` block — the.ics format is plain text from RFC 5545. If you only need attendees to get an invite, skip the file: `nylas calendar events create --participants` already sends a standard iCalendar invite. Make an.ics when you need a portable, attachable file.

Command references used in this guide: [`nylas calendar events show`](https://cli.nylas.com/docs/commands/calendar-events-show), [`nylas calendar events list`](https://cli.nylas.com/docs/commands/calendar-events-list), and [`nylas calendar events create`](https://cli.nylas.com/docs/commands/calendar-events-create).

## What is an ICS file?

An ICS file is a calendar event in iCalendar format, the text-based standard defined by [RFC 5545](https://datatracker.ietf.org/doc/html/rfc5545). It wraps one or more `VEVENT` blocks inside a `VCALENDAR` container, and every major calendar — Google, Outlook, Apple Calendar — reads it. Attach a `.ics` to an email and the recipient's client offers to add the event with one click, regardless of which calendar they use.

Because it's plain text, you don't need a library to produce one — you need the event's fields and the right line format. The Nylas CLI supplies the fields: `nylas calendar events show --id EVENT_ID --json` returns the title, start, end, location, and participants. From there, generating the file is string assembly with a handful of required properties.

## How do you build an ICS file from an event?

Build the file by reading the event JSON and emitting the required iCalendar properties: `UID`, `DTSTART`, `DTEND`, `SUMMARY`, and a `DTSTAMP`. Times use the UTC form `YYYYMMDDTHHMMSSZ`. A small script maps the JSON fields to those lines and writes the `.ics` — under 20 lines of shell or Python, no dependencies.

Keep the UID stable per event, since clients use it to de-duplicate and to match updates to an existing entry. If you regenerate the file for the same meeting, reuse the event's ID as the UID so an import updates rather than duplicates. The example pulls one event and writes a valid single-event calendar you can attach anywhere.

```bash
#!/usr/bin/env bash
# Read one event as JSON and emit a valid .ics
ev=$(nylas calendar events show --id event_abc123 --json)

uid=$(echo "$ev"   | jq -r '.id')
title=$(echo "$ev" | jq -r '.title')
start=$(echo "$ev" | jq -r '.when.start_time')   # epoch seconds
end=$(echo "$ev"   | jq -r '.when.end_time')
fmt() { date -u -r "$1" +%Y%m%dT%H%M%SZ; }        # epoch -> UTC ICS time

cat > event.ics <<EOF
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//yourapp//nylas-cli//EN
BEGIN:VEVENT
UID:$uid
DTSTAMP:$(date -u +%Y%m%dT%H%M%SZ)
DTSTART:$(fmt "$start")
DTEND:$(fmt "$end")
SUMMARY:$title
END:VEVENT
END:VCALENDAR
EOF
```

## When can you skip the ICS file entirely?

Skip the file when the goal is simply to invite people. Creating an event with participants — `nylas calendar events create --participants alice@x.com,bob@x.com` — makes the provider send each attendee a standard iCalendar invite, which is exactly what an attached `.ics` would do, but tracked on your calendar with RSVPs. You only hand-build a file when you need a portable artifact rather than a live event.

Generate a standalone `.ics` for cases the calendar can't cover: an “Add to calendar” download on a web page, an attachment in a transactional email, or an export for an offline import. For those, the file is the deliverable. For an actual meeting with attendees, let the create command send the invite and skip the assembly.

```bash
# If you just want attendees invited, this is the whole job:
nylas calendar events create \
  --title "Project kickoff" \
  --start 2026-06-20T15:00:00Z \
  --end 2026-06-20T16:00:00Z \
  --participants alice@example.com,bob@example.com
```

## Next steps

- [Create calendar invites](https://cli.nylas.com/guides/create-calendar-invites-cli) — send invites without building a file
- [CalDAV explained](https://cli.nylas.com/guides/caldav-explained) — the protocol behind iCalendar sync
- [Add conferencing to events](https://cli.nylas.com/guides/add-conferencing-to-events-cli) — attach a video link to an event
- [Manage calendar from the terminal](https://cli.nylas.com/guides/manage-calendar-from-terminal) — the full calendar workflow
- [Full command reference](https://cli.nylas.com/docs/commands) — every flag and subcommand documented
