Now you can fetch member data. You can choose which information to include using the expanded parameter:
// Fetch first page of members (50 members by default)let response = try await congregation.members.fetchAll( pageNumber: 1, pageSize: 50)print("Fetched \(response.members.count) members")for member in response.members { print("\(member.memberName ?? "Unknown") - \(member.phone ?? "No phone")")}
When you fetch members, you can choose which parts of their data you want by passing an array of MemberExpand values. This makes API calls faster and keeps your app efficient:
Expansion
Property on Member
What It Includes
.contactInformation
member.contactInformation
Phone, email, address, WhatsApp number
.employmentInformation
member.employmentInformation
Employment status, organization, occupation
.maritalInformation
member.maritalInformation
Marital status, spouse name, wedding anniversary
.discipleshipInformation
member.discipleshipInformation
Water baptism, courses completed, ministry involvement
If you don’t request a field expansion, that property will be nil in the member object. Always check for nil before accessing expanded fields.
do { let member = try await congregation.members.fetch(id: memberId)} catch MemberError.memberNotFound { print("Member not found")} catch MemberError.invalidMemberID { print("Invalid member ID format (must start with TKT)")} catch MemberError.fetchFailed(let error) { print("Failed to fetch member: \(error.localizedDescription)")} catch { print("Unexpected error: \(error)")}
CongregationKit uses a type-safe MemberID struct to ensure member IDs are valid:
import Congregation// Using the throwing initializerdo { let memberId = try MemberID(validating: "TKT123456") let member = try await congregation.members.fetch(id: memberId)} catch MemberError.invalidMemberID { print("Member ID must start with 'TKT'")}// Using the failable initializerif let memberId = MemberID(rawValue: "tkt123456") { // memberId.rawValue is automatically normalized to "TKT123456" let member = try await congregation.members.fetch(id: memberId)}
Member IDs are automatically normalized to uppercase (e.g., “tkt123” becomes “TKT123”).