> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tktchurch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get ICS File

> Download an ICS file for the event

## Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier (UUID) of the event
</ParamField>

## Response

Returns an ICS file containing the event details in iCalendar format. The response will have:

* Content-Type: `text/calendar; charset=utf-8`
* Content-Disposition: `attachment; filename="event.ics"`

The ICS file includes:

* Event title and description
* Start and end dates
* Location details
* Recurrence rules (if applicable)
* Reminders
* Organizer information

## Error Responses

<ResponseField name="error" type="object">
  Error details when the request fails

  <Expandable title="Error Object">
    <ResponseField name="status" type="integer">
      HTTP status code
    </ResponseField>

    <ResponseField name="reason" type="string">
      Error message explaining why the request failed
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  Common error cases:

  * 404 Not Found: Event not found
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.tktchurch.com/v1/events/123e4567-e89b-12d3-a456-426614174000/calendar.ics" \
    -H "Accept: text/calendar"
  ```

  ```javascript JavaScript theme={null}
  const downloadICSFile = async (eventId) => {
    const response = await fetch(
      `https://api.tktchurch.com/v1/events/${eventId}/calendar.ics`,
      {
        method: 'GET',
        headers: {
          'Accept': 'text/calendar'
        }
      }
    );

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.error.reason);
    }

    return response.text();
  };

  // Usage
  try {
    const icsContent = await downloadICSFile('123e4567-e89b-12d3-a456-426614174000');
    console.log('ICS file content:', icsContent);
  } catch (error) {
    console.error('Error:', error);
  }
  ```

  ```swift Swift theme={null}
  func downloadICSFile(eventId: UUID) async throws -> String {
      let urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/events/\(eventId)/calendar.ics")!)
      
      let (data, response) = try await URLSession.shared.data(for: urlRequest)
      guard let httpResponse = response as? HTTPURLResponse else {
          throw URLError(.badServerResponse)
      }
      
      if httpResponse.statusCode != 200 {
          throw URLError(.badServerResponse)
      }
      
      return String(data: data, encoding: .utf8) ?? ""
  }

  // Usage
  do {
      let icsContent = try await downloadICSFile(
          eventId: UUID(uuidString: "123e4567-e89b-12d3-a456-426614174000")!
      )
      print("ICS file content:", icsContent)
  } catch {
      print("Error:", error)
  }
  ```

  ```kotlin Kotlin theme={null}
  suspend fun downloadICSFile(eventId: String): String {
      val client = OkHttpClient()
      
      val request = Request.Builder()
          .url("https://api.tktchurch.com/v1/events/$eventId/calendar.ics")
          .get()
          .header("Accept", "text/calendar")
          .build()
      
      client.newCall(request).execute().use { response ->
          if (!response.isSuccessful) {
              val error = response.body?.string()?.fromJson<ErrorResponse>()
              throw Exception(error?.reason ?: "Failed to download ICS file")
          }
          
          return response.body?.string() ?: throw Exception("Empty response")
      }
  }

  // Usage
  try {
      val icsContent = downloadICSFile("123e4567-e89b-12d3-a456-426614174000")
      println("ICS file content: $icsContent")
  } catch (e: Exception) {
      println("Error: ${e.message}")
  }
  ```

  ```typescript React Native theme={null}
  import axios from 'axios';

  const downloadICSFile = async (eventId: string): Promise<string> => {
    try {
      const response = await axios.get(
        `https://api.tktchurch.com/v1/events/${eventId}/calendar.ics`,
        {
          headers: {
            'Accept': 'text/calendar'
          },
          responseType: 'text'
        }
      );
      return response.data;
    } catch (error) {
      if (axios.isAxiosError(error)) {
        throw new Error(error.response?.data?.error?.reason || 'Failed to download ICS file');
      }
      throw error;
    }
  };

  // Usage
  try {
    const icsContent = await downloadICSFile('123e4567-e89b-12d3-a456-426614174000');
    console.log('ICS file content:', icsContent);
  } catch (error) {
    console.error('Error:', error);
  }
  ```
</RequestExample>

<ResponseExample>
  ```text Response theme={null}
  BEGIN:VCALENDAR
  VERSION:2.0
  PRODID:-//TKT Church//Event Calendar//EN
  CALSCALE:GREGORIAN
  METHOD:PUBLISH
  BEGIN:VEVENT
  UID:123e4567-e89b-12d3-a456-426614174000
  DTSTAMP:20240101T000000Z
  DTSTART:20240107T100000Z
  DTEND:20240107T120000Z
  SUMMARY:Sunday Worship Service
  DESCRIPTION:Weekly Sunday worship service
  LOCATION:Main Sanctuary, 123 Church Street, New York, NY, USA, 10001
  STATUS:CONFIRMED
  ORGANIZER;CN=TKT Church:mailto:info@tktchurch.com
  RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=SU
  BEGIN:VALARM
  ACTION:DISPLAY
  DESCRIPTION:Reminder
  TRIGGER:-PT1440M
  END:VALARM
  BEGIN:VALARM
  ACTION:DISPLAY
  DESCRIPTION:Reminder
  TRIGGER:-PT60M
  END:VALARM
  END:VEVENT
  END:VCALENDAR
  ```

  ```json 404 Not Found theme={null}
  {
    "error": {
      "status": 404,
      "reason": "Event not found"
    }
  }
  ```
</ResponseExample>
