Elixir client for the Apple CloudKit API.
The public surface is intentionally small:
CloudKit.query_records(%{recordType: "Items"})
CloudKit.fetch_record("record_name")
CloudKit.create_record(%{recordType: "Items", fields: %{...}})
CloudKit.update_record("record_name", %{fields: %{...}})
CloudKit.delete_record("record_name")
CloudKit.upload_asset("file_path", "record_type", "field_name")
CloudKit.token()Configuration
config :cloud_kit,
container_id: System.get_env("CLOUDKIT_CONTAINER_ID"),
environment: "development", # or "production"
server_key_id: System.get_env("CLOUDKIT_SERVER_KEY_ID"),
private_key: System.get_env("CLOUDKIT_PRIVATE_KEY"),
base_url: "https://api.apple-cloudkit.com"Every function also accepts per-call opts that override the application config.
Summary
Functions
Create a new record.
Create a subscription for change notifications.
Create a custom zone.
Delete a record by record name.
Delete a subscription.
Delete a zone.
Download an asset from CloudKit.
Fetch a single record by record name.
List active subscriptions.
List zones in the database.
Query records from the CloudKit database.
Return a cached-per-call CloudKit access token (after the JWT → token exchange).
Update an existing record.
Upload an asset to CloudKit.
Types
Functions
Create a new record.
Parameters
record: Map containing:recordType- The record typerecordName- Optional unique record name (generated if not provided)fields- Map of field name to value
opts::zone_id- Zone ID for record
Examples
CloudKit.create_record(%{
recordType: "Items",
fields: %{
name: %{value: "New Item"},
price: %{value: 99.99, type: "DOUBLE"}
}
})
Create a subscription for change notifications.
Parameters
subscription: Map containing:subscriptionType- Type ("query" or "zone")recordType- For query subscriptions, the record typefilters- Optional filtersnotification- Notification configuration
opts: Optional configuration
Examples
CloudKit.create_subscription(%{
subscriptionType: "query",
recordType: "Items",
notification: %{
alertBody: "A new item was created"
}
})
Create a custom zone.
Parameters
zone_name: The zone nameopts: Optional configuration
Delete a record by record name.
Parameters
record_name: The unique record nameopts::record_type- The record type:zone_id- Zone ID for record
Delete a subscription.
Parameters
subscription_id: The subscription ID to deleteopts: Optional configuration
Delete a zone.
Parameters
zone_name: The zone name to deleteopts: Optional configuration
Download an asset from CloudKit.
Parameters
download_url: The download URL from an asset fieldopts: Download options
Examples
{:ok, content} = CloudKit.download_asset(record["fields"]["image"]["downloadURL"])
Fetch a single record by record name.
Parameters
record_name: The unique record nameopts::record_type- Optional record type:zone_id- Zone ID for record:desired_keys- List of field names to return
List active subscriptions.
Parameters
opts: Optional configuration
List zones in the database.
Parameters
opts: Optional configuration overrides
Query records from the CloudKit database.
Parameters
query: Map containing:recordType- The record type to queryfilterBy- Optional filter specificationsortBy- Optional sort specificationlimit- Maximum records to return (default 200)desiredKeys- Optional list of field names to return
opts::zone_id- Zone ID for record (defaults to default zone)
Examples
CloudKit.query_records(%{
recordType: "Items",
filterBy: [%{fieldName: "name", comparator: "EQUALS", fieldValue: %{value: "Test"}}],
limit: 50
})
Return a cached-per-call CloudKit access token (after the JWT → token exchange).
Update an existing record.
Parameters
record_name: The unique record nameupdates: Map of fields to updateopts::record_type- The record type:zone_id- Zone ID for record
Examples
CloudKit.update_record("record_123", %{
fields: %{
price: %{value: 149.99, type: "DOUBLE"}
}
})
Upload an asset to CloudKit.
Parameters
file_path: Path to the file to uploadrecord_type: The record type that will use this assetfield_name: The field name in the recordopts::zone_id- Zone ID:record_name- Optional record name to associate
Examples
CloudKit.upload_asset("/path/to/image.png", "Items", "image")