Databases

SERVER

The Databases service allows you to create structured collections of documents, query and filter lists of documents, and manage an advanced set of read and write access permissions.

All data returned by the Databases service are represented as structured JSON documents.

The Databases service can contain multiple databases, each database can contain multiple collections. A collection is a group of similarly structured documents. The accepted structure of documents is defined by collection attributes. The collection attributes help you ensure all your user-submitted data is validated and stored according to the collection structure.

Using Appwrite permissions architecture, you can assign read or write access to each collection or document in your project for either a specific user, team, user role, or even grant it with public access (any). You can learn more about how Appwrite handles permissions and access control.

Base URL
https://cloud.appwrite.io/v1

List databases

Get a list of all databases from the current Appwrite project. You can use the search parameter to filter your results.

  • Request
    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name

    • search string

      Search term to filter your list results. Max length: 256 chars.

  • Response
Endpoint
GET /databases
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.list(
    queries = listOf(), // optional
    search = "<SEARCH>" // optional
)

Create database

Create a new Database.

  • Request
    • databaseId string
      required

      Unique Id. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

    • name string
      required

      Database name. Max length: 128 chars.

    • enabled boolean

      Is the database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.

  • Response
Endpoint
POST /databases
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.create(
    databaseId = "<DATABASE_ID>",
    name = "<NAME>",
    enabled = false // optional
)

Get database

Get a database by its unique ID. This endpoint response returns a JSON object with the database metadata.

  • Request
    • databaseId string
      required

      Database ID.

  • Response
Endpoint
GET /databases/{databaseId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.get(
    databaseId = "<DATABASE_ID>"
)

Update database

Update a database by its unique ID.

  • Request
    • databaseId string
      required

      Database ID.

    • name string
      required

      Database name. Max length: 128 chars.

    • enabled boolean

      Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.

  • Response
Endpoint
PUT /databases/{databaseId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.update(
    databaseId = "<DATABASE_ID>",
    name = "<NAME>",
    enabled = false // optional
)

Delete database

Delete a database by its unique ID. Only API keys with with databases.write scope can delete a database.

  • Request
    • databaseId string
      required

      Database ID.

  • Response
    • 204 application/json
Endpoint
DELETE /databases/{databaseId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.delete(
    databaseId = "<DATABASE_ID>"
)

List collections

Get a list of all collections that belong to the provided databaseId. You can use the search parameter to filter your results.

  • Request
    • databaseId string
      required

      Database ID.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, enabled, documentSecurity

    • search string

      Search term to filter your list results. Max length: 256 chars.

  • Response
Endpoint
GET /databases/{databaseId}/collections
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.listCollections(
    databaseId = "<DATABASE_ID>",
    queries = listOf(), // optional
    search = "<SEARCH>" // optional
)

Create collection

Create a new Collection. Before using this route, you should create a new database resource using either a server integration API or directly from your database console.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Unique Id. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

    • name string
      required

      Collection name. Max length: 128 chars.

    • documentSecurity boolean

      Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. Learn more about permissions.

    • enabled boolean

      Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.

  • Response
Endpoint
POST /databases/{databaseId}/collections
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createCollection(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    name = "<NAME>",
    permissions = listOf("read("any")"), // optional
    documentSecurity = false, // optional
    enabled = false // optional
)

Get collection

Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.getCollection(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>"
)

Update collection

Update a collection by its unique ID.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

    • name string
      required

      Collection name. Max length: 128 chars.

    • documentSecurity boolean

      Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. Learn more about permissions.

    • enabled boolean

      Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.

  • Response
Endpoint
PUT /databases/{databaseId}/collections/{collectionId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateCollection(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    name = "<NAME>",
    permissions = listOf("read("any")"), // optional
    documentSecurity = false, // optional
    enabled = false // optional
)

Delete collection

Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

  • Response
    • 204 application/json
Endpoint
DELETE /databases/{databaseId}/collections/{collectionId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.deleteCollection(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>"
)

List attributes

List attributes in the collection.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key, type, size, required, array, status, error

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/attributes
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.listAttributes(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    queries = listOf() // optional
)

Create boolean attribute

Create a boolean attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default boolean

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/boolean
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createBooleanAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = false, // optional
    array = false // optional
)

Update boolean attribute

Update a boolean attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default boolean
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateBooleanAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = false,
    newKey = "" // optional
)

Create datetime attribute

Create a date time attribute according to the ISO 8601 standard.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string

      Default value for the attribute in ISO 8601 format. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/datetime
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createDatetimeAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "", // optional
    array = false // optional
)

Update dateTime attribute

Update a date time attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateDatetimeAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "",
    newKey = "" // optional
)

Create email attribute

Create an email attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/email
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createEmailAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "email@example.com", // optional
    array = false // optional
)

Update email attribute

Update an email attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/email/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateEmailAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "email@example.com",
    newKey = "" // optional
)

Create enum attribute

Create an enumeration attribute. The elements param acts as a white-list of accepted values for this attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • elements array
      required

      Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of 100 elements are allowed, each 255 characters long.

    • required boolean
      required

      Is attribute required?

    • default string

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/enum
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createEnumAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    elements = listOf(),
    required = false,
    default = "<DEFAULT>", // optional
    array = false // optional
)

Update enum attribute

Update an enum attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • elements array
      required

      Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of 100 elements are allowed, each 255 characters long.

    • required boolean
      required

      Is attribute required?

    • default string
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateEnumAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    elements = listOf(),
    required = false,
    default = "<DEFAULT>",
    newKey = "" // optional
)

Create float attribute

Create a float attribute. Optionally, minimum and maximum values can be provided.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • min number

      Minimum value to enforce on new documents

    • max number

      Maximum value to enforce on new documents

    • default number

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/float
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createFloatAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    min = 0, // optional
    max = 0, // optional
    default = 0, // optional
    array = false // optional
)

Update float attribute

Update a float attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • min number
      required

      Minimum value to enforce on new documents

    • max number
      required

      Maximum value to enforce on new documents

    • default number
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/float/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateFloatAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    min = 0,
    max = 0,
    default = 0,
    newKey = "" // optional
)

Create integer attribute

Create an integer attribute. Optionally, minimum and maximum values can be provided.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • min integer

      Minimum value to enforce on new documents

    • max integer

      Maximum value to enforce on new documents

    • default integer

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/integer
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createIntegerAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    min = 0, // optional
    max = 0, // optional
    default = 0, // optional
    array = false // optional
)

Update integer attribute

Update an integer attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • min integer
      required

      Minimum value to enforce on new documents

    • max integer
      required

      Maximum value to enforce on new documents

    • default integer
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateIntegerAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    min = 0,
    max = 0,
    default = 0,
    newKey = "" // optional
)

Create IP address attribute

Create IP address attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/ip
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createIpAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "", // optional
    array = false // optional
)

Update IP address attribute

Update an ip attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateIpAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "",
    newKey = "" // optional
)

Create relationship attribute

Create relationship attribute. Learn more about relationship attributes.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • relatedCollectionId string
      required

      Related Collection ID. You can create a new collection using the Database service server integration.

    • type string
      required

      Relation type

    • twoWay boolean

      Is Two Way?

    • key string

      Attribute Key.

    • twoWayKey string

      Two Way Attribute Key.

    • onDelete string

      Constraints option

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/relationship
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases
import io.appwrite.enums.RelationshipType

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createRelationshipAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    relatedCollectionId = "<RELATED_COLLECTION_ID>",
    type =  RelationshipType.ONETOONE,
    twoWay = false, // optional
    key = "", // optional
    twoWayKey = "", // optional
    onDelete = "cascade" // optional
)

Create string attribute

Create a string attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • size integer
      required

      Attribute size for text attributes, in number of characters.

    • required boolean
      required

      Is attribute required?

    • default string

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

    • encrypt boolean

      Toggle encryption for the attribute. Encryption enhances security by not storing any plain text values in the database. However, encrypted attributes cannot be queried.

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/string
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createStringAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    size = 1,
    required = false,
    default = "<DEFAULT>", // optional
    array = false, // optional
    encrypt = false // optional
)

Update string attribute

Update a string attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • size integer

      Maximum size of the string attribute.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/string/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateStringAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "<DEFAULT>",
    size = 0, // optional
    newKey = "" // optional
)

Create URL attribute

Create a URL attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • array boolean

      Is attribute an array?

  • Response
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/attributes/url
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createUrlAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "https://example.com", // optional
    array = false // optional
)

Update URL attribute

Update an url attribute. Changing the default value will not update already existing documents.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • required boolean
      required

      Is attribute required?

    • default string
      required

      Default value for attribute when not provided. Cannot be set when attribute is required.

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/url/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateUrlAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    required = false,
    default = "https://example.com",
    newKey = "" // optional
)

Get attribute

Get attribute by ID.

Endpoint
GET /databases/{databaseId}/collections/{collectionId}/attributes/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.getAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = ""
)

Delete attribute

Deletes an attribute.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

  • Response
    • 204 application/json
Endpoint
DELETE /databases/{databaseId}/collections/{collectionId}/attributes/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.deleteAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = ""
)

Update relationship attribute

Update relationship attribute. Learn more about relationship attributes.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Attribute Key.

    • onDelete string

      Constraints option

    • newKey string

      New attribute key.

  • Response
    • 200 application/json
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.updateRelationshipAttribute(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    onDelete = "cascade", // optional
    newKey = "" // optional
)

List documents

Get a list of all the user's documents in a given collection. You can use the query params to filter your results.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/documents
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setSession("") // The user session to authenticate with

val databases = Databases(client)

val response = databases.listDocuments(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    queries = listOf() // optional
)

Create document

Create a new Document. Before using this route, you should create a new collection resource using either a server integration API or directly from your database console.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration. Make sure to define attributes before creating documents.

    • documentId string
      required

      Document ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

    • data object
      required

      Document data as JSON object.

    • permissions array

      An array of permissions strings. By default, only the current user is granted all permissions. Learn more about permissions.

  • Response
  • Rate limits

    This endpoint is not limited when using Server SDKs with API keys. If you are using SSR with setSession, these rate limits will still apply. Learn more about SSR rate limits.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes 120 requests IP + METHOD + URL + USER ID
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/documents
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setSession("") // The user session to authenticate with

val databases = Databases(client)

val response = databases.createDocument(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    documentId = "<DOCUMENT_ID>",
    data = mapOf( "a" to "b" ),
    permissions = listOf("read("any")") // optional
)

Get document

Get a document by its unique ID. This endpoint response returns a JSON object with the document data.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • documentId string
      required

      Document ID.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long.

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setSession("") // The user session to authenticate with

val databases = Databases(client)

val response = databases.getDocument(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    documentId = "<DOCUMENT_ID>",
    queries = listOf() // optional
)

Update document

Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID.

    • documentId string
      required

      Document ID.

    • data object

      Document data as JSON object. Include only attribute and value pairs to be updated.

  • Response
  • Rate limits

    This endpoint is not limited when using Server SDKs with API keys. If you are using SSR with setSession, these rate limits will still apply. Learn more about SSR rate limits.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes 120 requests IP + METHOD + URL + USER ID
Endpoint
PATCH /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setSession("") // The user session to authenticate with

val databases = Databases(client)

val response = databases.updateDocument(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    documentId = "<DOCUMENT_ID>",
    data = mapOf( "a" to "b" ), // optional
    permissions = listOf("read("any")") // optional
)

Delete document

Delete a document by its unique ID.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • documentId string
      required

      Document ID.

  • Response
    • 204 application/json
  • Rate limits

    This endpoint is not limited when using Server SDKs with API keys. If you are using SSR with setSession, these rate limits will still apply. Learn more about SSR rate limits.

    The limit is applied for each unique limit key.

    Time frame
    Attempts
    Key
    1 minutes 60 requests IP + METHOD + URL + USER ID
Endpoint
DELETE /databases/{databaseId}/collections/{collectionId}/documents/{documentId}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setSession("") // The user session to authenticate with

val databases = Databases(client)

val response = databases.deleteDocument(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    documentId = "<DOCUMENT_ID>"
)

List indexes

List indexes in the collection.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • queries array

      Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key, type, status, attributes, error

  • Response
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/indexes
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.listIndexes(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    queries = listOf() // optional
)

Create index

Creates an index on the attributes listed. Your index should include all the attributes you will query in a single request. Attributes can be key, fulltext, and unique.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Index Key.

    • type string
      required

      Index type.

    • attributes array
      required

      Array of attributes to index. Maximum of 100 attributes are allowed, each 32 characters long.

    • orders array

      Array of index orders. Maximum of 100 orders are allowed.

  • Response
    • 202 application/json
Endpoint
POST /databases/{databaseId}/collections/{collectionId}/indexes
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases
import io.appwrite.enums.IndexType

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.createIndex(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = "",
    type =  IndexType.KEY,
    attributes = listOf(),
    orders = listOf() // optional
)

Get index

Get index by ID.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Index Key.

  • Response
    • 200 application/json
Endpoint
GET /databases/{databaseId}/collections/{collectionId}/indexes/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.getIndex(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = ""
)

Delete index

Delete an index.

  • Request
    • databaseId string
      required

      Database ID.

    • collectionId string
      required

      Collection ID. You can create a new collection using the Database service server integration.

    • key string
      required

      Index Key.

  • Response
    • 204 application/json
Endpoint
DELETE /databases/{databaseId}/collections/{collectionId}/indexes/{key}
Kotlin
import io.appwrite.Client
import io.appwrite.coroutines.CoroutineCallback
import io.appwrite.services.Databases

val client = Client()
    .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
    .setProject("<YOUR_PROJECT_ID>") // Your project ID
    .setKey("<YOUR_API_KEY>") // Your secret API key

val databases = Databases(client)

val response = databases.deleteIndex(
    databaseId = "<DATABASE_ID>",
    collectionId = "<COLLECTION_ID>",
    key = ""
)