curl -X POST "https://api.tktchurch.com/v1/events" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-d '{
"title": "Sunday Worship Service",
"description": "Weekly Sunday worship service",
"startDate": "2024-01-07T10:00:00Z",
"endDate": "2024-01-07T12:00:00Z",
"timezone": "America/New_York",
"location": {
"name": "Main Sanctuary",
"address": "123 Church Street",
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"type": "service",
"recurrence": {
"frequency": "weekly",
"interval": 1,
"byDay": ["SU"]
},
"reminders": [
{
"type": "email",
"minutes": 1440
},
{
"type": "notification",
"minutes": 60
}
],
"tags": ["worship", "sunday-service"],
"maxCapacity": 500,
"requiresGeolocation": true,
"geofenceRadius": 100
}'
const createEvent = async (accessToken, eventData) => {
const response = await fetch(
'https://api.tktchurch.com/v1/events',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(eventData)
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.error.reason);
}
return response.json();
};
// Usage
try {
const event = await createEvent(accessToken, {
title: 'Sunday Worship Service',
description: 'Weekly Sunday worship service',
startDate: '2024-01-07T10:00:00Z',
endDate: '2024-01-07T12:00:00Z',
timezone: 'America/New_York',
location: {
name: 'Main Sanctuary',
address: '123 Church Street',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '10001',
coordinates: {
latitude: 40.7128,
longitude: -74.0060
}
},
type: 'service',
recurrence: {
frequency: 'weekly',
interval: 1,
byDay: ['SU']
},
reminders: [
{
type: 'email',
minutes: 1440
},
{
type: 'notification',
minutes: 60
}
],
tags: ['worship', 'sunday-service'],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
});
console.log('Created event:', event);
} catch (error) {
console.error('Error:', error);
}
struct CreateEventRequest: Codable {
let title: String
let description: String
let startDate: String
let endDate: String
let timezone: String
let location: Location
let type: String
let recurrence: Recurrence?
let reminders: [Reminder]
let tags: [String]
let maxCapacity: Int?
let requiresGeolocation: Bool
let geofenceRadius: Double?
}
func createEvent(accessToken: String, event: CreateEventRequest) async throws -> Event {
var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/events")!)
urlRequest.httpMethod = "POST"
urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.httpBody = try JSONEncoder().encode(event)
let (data, response) = try await URLSession.shared.data(for: urlRequest)
guard let httpResponse = response as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}
if httpResponse.statusCode != 200 {
let error = try JSONDecoder().decode(ErrorResponse.self, from: data)
throw error
}
return try JSONDecoder().decode(Event.self, from: data)
}
// Usage
do {
let event = try await createEvent(
accessToken: accessToken,
event: CreateEventRequest(
title: "Sunday Worship Service",
description: "Weekly Sunday worship service",
startDate: "2024-01-07T10:00:00Z",
endDate: "2024-01-07T12:00:00Z",
timezone: "America/New_York",
location: Location(
name: "Main Sanctuary",
address: "123 Church Street",
city: "New York",
state: "NY",
country: "USA",
postalCode: "10001",
coordinates: Coordinates(
latitude: 40.7128,
longitude: -74.0060
)
),
type: "service",
recurrence: Recurrence(
frequency: "weekly",
interval: 1,
byDay: ["SU"]
),
reminders: [
Reminder(type: "email", minutes: 1440),
Reminder(type: "notification", minutes: 60)
],
tags: ["worship", "sunday-service"],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
)
)
print("Created event:", event)
} catch {
print("Error:", error)
}
data class CreateEventRequest(
val title: String,
val description: String,
val startDate: String,
val endDate: String,
val timezone: String,
val location: Location,
val type: String,
val recurrence: Recurrence?,
val reminders: List<Reminder>,
val tags: List<String>,
val maxCapacity: Int?,
val requiresGeolocation: Boolean,
val geofenceRadius: Double?
)
suspend fun createEvent(accessToken: String, event: CreateEventRequest): Event {
val client = OkHttpClient()
val requestBody = Json.encodeToString(event)
val request = Request.Builder()
.url("https://api.tktchurch.com/v1/events")
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
.header("Authorization", "Bearer $accessToken")
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) {
val error = response.body?.string()?.fromJson<ErrorResponse>()
throw Exception(error?.reason ?: "Failed to create event")
}
return response.body?.string()?.fromJson<Event>()
?: throw Exception("Empty response")
}
}
// Usage
try {
val event = createEvent(
accessToken = accessToken,
event = CreateEventRequest(
title = "Sunday Worship Service",
description = "Weekly Sunday worship service",
startDate = "2024-01-07T10:00:00Z",
endDate = "2024-01-07T12:00:00Z",
timezone = "America/New_York",
location = Location(
name = "Main Sanctuary",
address = "123 Church Street",
city = "New York",
state = "NY",
country = "USA",
postalCode = "10001",
coordinates = Coordinates(
latitude = 40.7128,
longitude = -74.0060
)
),
type = "service",
recurrence = Recurrence(
frequency = "weekly",
interval = 1,
byDay = listOf("SU")
),
reminders = listOf(
Reminder(type = "email", minutes = 1440),
Reminder(type = "notification", minutes = 60)
),
tags = listOf("worship", "sunday-service"),
maxCapacity = 500,
requiresGeolocation = true,
geofenceRadius = 100.0
)
)
println("Created event: $event")
} catch (e: Exception) {
println("Error: ${e.message}")
}
import axios from 'axios';
interface CreateEventRequest {
title: string;
description: string;
startDate: string;
endDate: string;
timezone: string;
location: {
name: string;
address: string;
city: string;
state: string;
country: string;
postalCode: string;
coordinates: {
latitude: number;
longitude: number;
};
virtualMeetingUrl?: string;
};
type: 'service' | 'meeting' | 'concert' | 'workshop' | 'conference' | 'social' | 'other';
recurrence?: {
frequency: 'daily' | 'weekly' | 'monthly' | 'yearly';
interval: number;
until?: string;
count?: number;
byDay?: string[];
byMonth?: number[];
byMonthDay?: number[];
excludeDates?: string[];
};
reminders: Array<{
type: 'email' | 'notification' | 'sms';
minutes: number;
}>;
tags: string[];
maxCapacity?: number;
requiresGeolocation: boolean;
geofenceRadius?: number;
thumbnailId?: string;
}
const createEvent = async (
accessToken: string,
event: CreateEventRequest
): Promise<Event> => {
try {
const response = await axios.post(
'https://api.tktchurch.com/v1/events',
event,
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
}
);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error?.reason || 'Failed to create event');
}
throw error;
}
};
// Usage
try {
const event = await createEvent(accessToken, {
title: 'Sunday Worship Service',
description: 'Weekly Sunday worship service',
startDate: '2024-01-07T10:00:00Z',
endDate: '2024-01-07T12:00:00Z',
timezone: 'America/New_York',
location: {
name: 'Main Sanctuary',
address: '123 Church Street',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '10001',
coordinates: {
latitude: 40.7128,
longitude: -74.0060
}
},
type: 'service',
recurrence: {
frequency: 'weekly',
interval: 1,
byDay: ['SU']
},
reminders: [
{
type: 'email',
minutes: 1440
},
{
type: 'notification',
minutes: 60
}
],
tags: ['worship', 'sunday-service'],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
});
console.log('Created event:', event);
} catch (error) {
console.error('Error:', error);
}
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"title": "Sunday Worship Service",
"description": "Weekly Sunday worship service",
"startDate": "2024-01-07T10:00:00Z",
"endDate": "2024-01-07T12:00:00Z",
"timezone": "America/New_York",
"location": {
"name": "Main Sanctuary",
"address": "123 Church Street",
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"type": "service",
"status": "scheduled",
"recurrence": {
"frequency": "weekly",
"interval": 1,
"byDay": ["SU"]
},
"reminders": [
{
"type": "email",
"minutes": 1440
},
{
"type": "notification",
"minutes": 60
}
],
"calendarLinks": {
"google": "https://calendar.google.com/...",
"apple": "webcal://...",
"outlook": "https://outlook.office.com/...",
"yahoo": "https://calendar.yahoo.com/...",
"ics": "https://api.tktchurch.com/v1/events/123/calendar.ics"
},
"tags": ["worship", "sunday-service"],
"maxCapacity": 500,
"requiresGeolocation": true,
"geofenceRadius": 100,
"createdByUserId": "456e7890-f12g-34h5-i678-912345678901",
"updatedByUserId": "456e7890-f12g-34h5-i678-912345678901",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
{
"error": {
"status": 400,
"reason": "Invalid ISO8601 format for startDate"
}
}
{
"error": {
"status": 401,
"reason": "Invalid or expired access token"
}
}
{
"error": {
"status": 403,
"reason": "Missing required permission: createEvent"
}
}
Events
Create Event
Create a new church event
POST
/
events
curl -X POST "https://api.tktchurch.com/v1/events" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-d '{
"title": "Sunday Worship Service",
"description": "Weekly Sunday worship service",
"startDate": "2024-01-07T10:00:00Z",
"endDate": "2024-01-07T12:00:00Z",
"timezone": "America/New_York",
"location": {
"name": "Main Sanctuary",
"address": "123 Church Street",
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"type": "service",
"recurrence": {
"frequency": "weekly",
"interval": 1,
"byDay": ["SU"]
},
"reminders": [
{
"type": "email",
"minutes": 1440
},
{
"type": "notification",
"minutes": 60
}
],
"tags": ["worship", "sunday-service"],
"maxCapacity": 500,
"requiresGeolocation": true,
"geofenceRadius": 100
}'
const createEvent = async (accessToken, eventData) => {
const response = await fetch(
'https://api.tktchurch.com/v1/events',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(eventData)
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.error.reason);
}
return response.json();
};
// Usage
try {
const event = await createEvent(accessToken, {
title: 'Sunday Worship Service',
description: 'Weekly Sunday worship service',
startDate: '2024-01-07T10:00:00Z',
endDate: '2024-01-07T12:00:00Z',
timezone: 'America/New_York',
location: {
name: 'Main Sanctuary',
address: '123 Church Street',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '10001',
coordinates: {
latitude: 40.7128,
longitude: -74.0060
}
},
type: 'service',
recurrence: {
frequency: 'weekly',
interval: 1,
byDay: ['SU']
},
reminders: [
{
type: 'email',
minutes: 1440
},
{
type: 'notification',
minutes: 60
}
],
tags: ['worship', 'sunday-service'],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
});
console.log('Created event:', event);
} catch (error) {
console.error('Error:', error);
}
struct CreateEventRequest: Codable {
let title: String
let description: String
let startDate: String
let endDate: String
let timezone: String
let location: Location
let type: String
let recurrence: Recurrence?
let reminders: [Reminder]
let tags: [String]
let maxCapacity: Int?
let requiresGeolocation: Bool
let geofenceRadius: Double?
}
func createEvent(accessToken: String, event: CreateEventRequest) async throws -> Event {
var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/events")!)
urlRequest.httpMethod = "POST"
urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.httpBody = try JSONEncoder().encode(event)
let (data, response) = try await URLSession.shared.data(for: urlRequest)
guard let httpResponse = response as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}
if httpResponse.statusCode != 200 {
let error = try JSONDecoder().decode(ErrorResponse.self, from: data)
throw error
}
return try JSONDecoder().decode(Event.self, from: data)
}
// Usage
do {
let event = try await createEvent(
accessToken: accessToken,
event: CreateEventRequest(
title: "Sunday Worship Service",
description: "Weekly Sunday worship service",
startDate: "2024-01-07T10:00:00Z",
endDate: "2024-01-07T12:00:00Z",
timezone: "America/New_York",
location: Location(
name: "Main Sanctuary",
address: "123 Church Street",
city: "New York",
state: "NY",
country: "USA",
postalCode: "10001",
coordinates: Coordinates(
latitude: 40.7128,
longitude: -74.0060
)
),
type: "service",
recurrence: Recurrence(
frequency: "weekly",
interval: 1,
byDay: ["SU"]
),
reminders: [
Reminder(type: "email", minutes: 1440),
Reminder(type: "notification", minutes: 60)
],
tags: ["worship", "sunday-service"],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
)
)
print("Created event:", event)
} catch {
print("Error:", error)
}
data class CreateEventRequest(
val title: String,
val description: String,
val startDate: String,
val endDate: String,
val timezone: String,
val location: Location,
val type: String,
val recurrence: Recurrence?,
val reminders: List<Reminder>,
val tags: List<String>,
val maxCapacity: Int?,
val requiresGeolocation: Boolean,
val geofenceRadius: Double?
)
suspend fun createEvent(accessToken: String, event: CreateEventRequest): Event {
val client = OkHttpClient()
val requestBody = Json.encodeToString(event)
val request = Request.Builder()
.url("https://api.tktchurch.com/v1/events")
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
.header("Authorization", "Bearer $accessToken")
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) {
val error = response.body?.string()?.fromJson<ErrorResponse>()
throw Exception(error?.reason ?: "Failed to create event")
}
return response.body?.string()?.fromJson<Event>()
?: throw Exception("Empty response")
}
}
// Usage
try {
val event = createEvent(
accessToken = accessToken,
event = CreateEventRequest(
title = "Sunday Worship Service",
description = "Weekly Sunday worship service",
startDate = "2024-01-07T10:00:00Z",
endDate = "2024-01-07T12:00:00Z",
timezone = "America/New_York",
location = Location(
name = "Main Sanctuary",
address = "123 Church Street",
city = "New York",
state = "NY",
country = "USA",
postalCode = "10001",
coordinates = Coordinates(
latitude = 40.7128,
longitude = -74.0060
)
),
type = "service",
recurrence = Recurrence(
frequency = "weekly",
interval = 1,
byDay = listOf("SU")
),
reminders = listOf(
Reminder(type = "email", minutes = 1440),
Reminder(type = "notification", minutes = 60)
),
tags = listOf("worship", "sunday-service"),
maxCapacity = 500,
requiresGeolocation = true,
geofenceRadius = 100.0
)
)
println("Created event: $event")
} catch (e: Exception) {
println("Error: ${e.message}")
}
import axios from 'axios';
interface CreateEventRequest {
title: string;
description: string;
startDate: string;
endDate: string;
timezone: string;
location: {
name: string;
address: string;
city: string;
state: string;
country: string;
postalCode: string;
coordinates: {
latitude: number;
longitude: number;
};
virtualMeetingUrl?: string;
};
type: 'service' | 'meeting' | 'concert' | 'workshop' | 'conference' | 'social' | 'other';
recurrence?: {
frequency: 'daily' | 'weekly' | 'monthly' | 'yearly';
interval: number;
until?: string;
count?: number;
byDay?: string[];
byMonth?: number[];
byMonthDay?: number[];
excludeDates?: string[];
};
reminders: Array<{
type: 'email' | 'notification' | 'sms';
minutes: number;
}>;
tags: string[];
maxCapacity?: number;
requiresGeolocation: boolean;
geofenceRadius?: number;
thumbnailId?: string;
}
const createEvent = async (
accessToken: string,
event: CreateEventRequest
): Promise<Event> => {
try {
const response = await axios.post(
'https://api.tktchurch.com/v1/events',
event,
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
}
);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error?.reason || 'Failed to create event');
}
throw error;
}
};
// Usage
try {
const event = await createEvent(accessToken, {
title: 'Sunday Worship Service',
description: 'Weekly Sunday worship service',
startDate: '2024-01-07T10:00:00Z',
endDate: '2024-01-07T12:00:00Z',
timezone: 'America/New_York',
location: {
name: 'Main Sanctuary',
address: '123 Church Street',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '10001',
coordinates: {
latitude: 40.7128,
longitude: -74.0060
}
},
type: 'service',
recurrence: {
frequency: 'weekly',
interval: 1,
byDay: ['SU']
},
reminders: [
{
type: 'email',
minutes: 1440
},
{
type: 'notification',
minutes: 60
}
],
tags: ['worship', 'sunday-service'],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
});
console.log('Created event:', event);
} catch (error) {
console.error('Error:', error);
}
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"title": "Sunday Worship Service",
"description": "Weekly Sunday worship service",
"startDate": "2024-01-07T10:00:00Z",
"endDate": "2024-01-07T12:00:00Z",
"timezone": "America/New_York",
"location": {
"name": "Main Sanctuary",
"address": "123 Church Street",
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"type": "service",
"status": "scheduled",
"recurrence": {
"frequency": "weekly",
"interval": 1,
"byDay": ["SU"]
},
"reminders": [
{
"type": "email",
"minutes": 1440
},
{
"type": "notification",
"minutes": 60
}
],
"calendarLinks": {
"google": "https://calendar.google.com/...",
"apple": "webcal://...",
"outlook": "https://outlook.office.com/...",
"yahoo": "https://calendar.yahoo.com/...",
"ics": "https://api.tktchurch.com/v1/events/123/calendar.ics"
},
"tags": ["worship", "sunday-service"],
"maxCapacity": 500,
"requiresGeolocation": true,
"geofenceRadius": 100,
"createdByUserId": "456e7890-f12g-34h5-i678-912345678901",
"updatedByUserId": "456e7890-f12g-34h5-i678-912345678901",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
{
"error": {
"status": 400,
"reason": "Invalid ISO8601 format for startDate"
}
}
{
"error": {
"status": 401,
"reason": "Invalid or expired access token"
}
}
{
"error": {
"status": 403,
"reason": "Missing required permission: createEvent"
}
}
This endpoint requires authentication and the
createEvent permission.Request Body
string
required
Event title
string
required
Event description
string
required
Event start date and time in ISO 8601 format
string
required
Event end date and time in ISO 8601 format
string
required
Event timezone (e.g., “America/New_York”)
object
required
Event location details
Show Location Object
Show Location Object
string
required
Event type. One of:
service: Church servicemeeting: Meetingconcert: Concertworkshop: Workshopconference: Conferencesocial: Social eventother: Other event type
string
Event status. One of:
scheduled(default): Default status for upcoming eventscancelled: Cancelled eventspostponed: Postponed eventsrescheduled: Rescheduled events
object
Event recurrence details
Show Recurrence Object
Show Recurrence Object
string
required
Recurrence frequency. One of:
daily, weekly, monthly, yearlyinteger
required
Interval between occurrences
string
End date for recurrence (ISO 8601)
integer
Number of occurrences
array
Days of week (SU, MO, TU, WE, TH, FR, SA)
array
Months (1-12)
array
Days of month
array
Excluded dates (ISO 8601)
array
array
array
Array of event tags
integer
Maximum number of attendees (if applicable)
boolean
Whether geolocation is required for attendance
number
Geofence radius in meters (if applicable)
string
UUID of the uploaded thumbnail file
Response
Returns the created event object. See Get Event Details for the response format.Error Responses
object
Common error cases:
- 400 Bad Request: Invalid request body or validation errors
- 401 Unauthorized: Missing or invalid access token
- 403 Forbidden: Insufficient permissions
curl -X POST "https://api.tktchurch.com/v1/events" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-d '{
"title": "Sunday Worship Service",
"description": "Weekly Sunday worship service",
"startDate": "2024-01-07T10:00:00Z",
"endDate": "2024-01-07T12:00:00Z",
"timezone": "America/New_York",
"location": {
"name": "Main Sanctuary",
"address": "123 Church Street",
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"type": "service",
"recurrence": {
"frequency": "weekly",
"interval": 1,
"byDay": ["SU"]
},
"reminders": [
{
"type": "email",
"minutes": 1440
},
{
"type": "notification",
"minutes": 60
}
],
"tags": ["worship", "sunday-service"],
"maxCapacity": 500,
"requiresGeolocation": true,
"geofenceRadius": 100
}'
const createEvent = async (accessToken, eventData) => {
const response = await fetch(
'https://api.tktchurch.com/v1/events',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(eventData)
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.error.reason);
}
return response.json();
};
// Usage
try {
const event = await createEvent(accessToken, {
title: 'Sunday Worship Service',
description: 'Weekly Sunday worship service',
startDate: '2024-01-07T10:00:00Z',
endDate: '2024-01-07T12:00:00Z',
timezone: 'America/New_York',
location: {
name: 'Main Sanctuary',
address: '123 Church Street',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '10001',
coordinates: {
latitude: 40.7128,
longitude: -74.0060
}
},
type: 'service',
recurrence: {
frequency: 'weekly',
interval: 1,
byDay: ['SU']
},
reminders: [
{
type: 'email',
minutes: 1440
},
{
type: 'notification',
minutes: 60
}
],
tags: ['worship', 'sunday-service'],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
});
console.log('Created event:', event);
} catch (error) {
console.error('Error:', error);
}
struct CreateEventRequest: Codable {
let title: String
let description: String
let startDate: String
let endDate: String
let timezone: String
let location: Location
let type: String
let recurrence: Recurrence?
let reminders: [Reminder]
let tags: [String]
let maxCapacity: Int?
let requiresGeolocation: Bool
let geofenceRadius: Double?
}
func createEvent(accessToken: String, event: CreateEventRequest) async throws -> Event {
var urlRequest = URLRequest(url: URL(string: "https://api.tktchurch.com/v1/events")!)
urlRequest.httpMethod = "POST"
urlRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
urlRequest.httpBody = try JSONEncoder().encode(event)
let (data, response) = try await URLSession.shared.data(for: urlRequest)
guard let httpResponse = response as? HTTPURLResponse else {
throw URLError(.badServerResponse)
}
if httpResponse.statusCode != 200 {
let error = try JSONDecoder().decode(ErrorResponse.self, from: data)
throw error
}
return try JSONDecoder().decode(Event.self, from: data)
}
// Usage
do {
let event = try await createEvent(
accessToken: accessToken,
event: CreateEventRequest(
title: "Sunday Worship Service",
description: "Weekly Sunday worship service",
startDate: "2024-01-07T10:00:00Z",
endDate: "2024-01-07T12:00:00Z",
timezone: "America/New_York",
location: Location(
name: "Main Sanctuary",
address: "123 Church Street",
city: "New York",
state: "NY",
country: "USA",
postalCode: "10001",
coordinates: Coordinates(
latitude: 40.7128,
longitude: -74.0060
)
),
type: "service",
recurrence: Recurrence(
frequency: "weekly",
interval: 1,
byDay: ["SU"]
),
reminders: [
Reminder(type: "email", minutes: 1440),
Reminder(type: "notification", minutes: 60)
],
tags: ["worship", "sunday-service"],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
)
)
print("Created event:", event)
} catch {
print("Error:", error)
}
data class CreateEventRequest(
val title: String,
val description: String,
val startDate: String,
val endDate: String,
val timezone: String,
val location: Location,
val type: String,
val recurrence: Recurrence?,
val reminders: List<Reminder>,
val tags: List<String>,
val maxCapacity: Int?,
val requiresGeolocation: Boolean,
val geofenceRadius: Double?
)
suspend fun createEvent(accessToken: String, event: CreateEventRequest): Event {
val client = OkHttpClient()
val requestBody = Json.encodeToString(event)
val request = Request.Builder()
.url("https://api.tktchurch.com/v1/events")
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
.header("Authorization", "Bearer $accessToken")
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) {
val error = response.body?.string()?.fromJson<ErrorResponse>()
throw Exception(error?.reason ?: "Failed to create event")
}
return response.body?.string()?.fromJson<Event>()
?: throw Exception("Empty response")
}
}
// Usage
try {
val event = createEvent(
accessToken = accessToken,
event = CreateEventRequest(
title = "Sunday Worship Service",
description = "Weekly Sunday worship service",
startDate = "2024-01-07T10:00:00Z",
endDate = "2024-01-07T12:00:00Z",
timezone = "America/New_York",
location = Location(
name = "Main Sanctuary",
address = "123 Church Street",
city = "New York",
state = "NY",
country = "USA",
postalCode = "10001",
coordinates = Coordinates(
latitude = 40.7128,
longitude = -74.0060
)
),
type = "service",
recurrence = Recurrence(
frequency = "weekly",
interval = 1,
byDay = listOf("SU")
),
reminders = listOf(
Reminder(type = "email", minutes = 1440),
Reminder(type = "notification", minutes = 60)
),
tags = listOf("worship", "sunday-service"),
maxCapacity = 500,
requiresGeolocation = true,
geofenceRadius = 100.0
)
)
println("Created event: $event")
} catch (e: Exception) {
println("Error: ${e.message}")
}
import axios from 'axios';
interface CreateEventRequest {
title: string;
description: string;
startDate: string;
endDate: string;
timezone: string;
location: {
name: string;
address: string;
city: string;
state: string;
country: string;
postalCode: string;
coordinates: {
latitude: number;
longitude: number;
};
virtualMeetingUrl?: string;
};
type: 'service' | 'meeting' | 'concert' | 'workshop' | 'conference' | 'social' | 'other';
recurrence?: {
frequency: 'daily' | 'weekly' | 'monthly' | 'yearly';
interval: number;
until?: string;
count?: number;
byDay?: string[];
byMonth?: number[];
byMonthDay?: number[];
excludeDates?: string[];
};
reminders: Array<{
type: 'email' | 'notification' | 'sms';
minutes: number;
}>;
tags: string[];
maxCapacity?: number;
requiresGeolocation: boolean;
geofenceRadius?: number;
thumbnailId?: string;
}
const createEvent = async (
accessToken: string,
event: CreateEventRequest
): Promise<Event> => {
try {
const response = await axios.post(
'https://api.tktchurch.com/v1/events',
event,
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
}
);
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error?.reason || 'Failed to create event');
}
throw error;
}
};
// Usage
try {
const event = await createEvent(accessToken, {
title: 'Sunday Worship Service',
description: 'Weekly Sunday worship service',
startDate: '2024-01-07T10:00:00Z',
endDate: '2024-01-07T12:00:00Z',
timezone: 'America/New_York',
location: {
name: 'Main Sanctuary',
address: '123 Church Street',
city: 'New York',
state: 'NY',
country: 'USA',
postalCode: '10001',
coordinates: {
latitude: 40.7128,
longitude: -74.0060
}
},
type: 'service',
recurrence: {
frequency: 'weekly',
interval: 1,
byDay: ['SU']
},
reminders: [
{
type: 'email',
minutes: 1440
},
{
type: 'notification',
minutes: 60
}
],
tags: ['worship', 'sunday-service'],
maxCapacity: 500,
requiresGeolocation: true,
geofenceRadius: 100
});
console.log('Created event:', event);
} catch (error) {
console.error('Error:', error);
}
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"title": "Sunday Worship Service",
"description": "Weekly Sunday worship service",
"startDate": "2024-01-07T10:00:00Z",
"endDate": "2024-01-07T12:00:00Z",
"timezone": "America/New_York",
"location": {
"name": "Main Sanctuary",
"address": "123 Church Street",
"city": "New York",
"state": "NY",
"country": "USA",
"postalCode": "10001",
"coordinates": {
"latitude": 40.7128,
"longitude": -74.0060
}
},
"type": "service",
"status": "scheduled",
"recurrence": {
"frequency": "weekly",
"interval": 1,
"byDay": ["SU"]
},
"reminders": [
{
"type": "email",
"minutes": 1440
},
{
"type": "notification",
"minutes": 60
}
],
"calendarLinks": {
"google": "https://calendar.google.com/...",
"apple": "webcal://...",
"outlook": "https://outlook.office.com/...",
"yahoo": "https://calendar.yahoo.com/...",
"ics": "https://api.tktchurch.com/v1/events/123/calendar.ics"
},
"tags": ["worship", "sunday-service"],
"maxCapacity": 500,
"requiresGeolocation": true,
"geofenceRadius": 100,
"createdByUserId": "456e7890-f12g-34h5-i678-912345678901",
"updatedByUserId": "456e7890-f12g-34h5-i678-912345678901",
"createdAt": "2024-01-01T00:00:00Z",
"updatedAt": "2024-01-01T00:00:00Z"
}
{
"error": {
"status": 400,
"reason": "Invalid ISO8601 format for startDate"
}
}
{
"error": {
"status": 401,
"reason": "Invalid or expired access token"
}
}
{
"error": {
"status": 403,
"reason": "Missing required permission: createEvent"
}
}
