We're having lots of fun on GitHub! Come and star us! ⭐️
Docs

Getting Started for Server

Appwrite is a development platform providing you easy yet powerful API and management console to get your next project up and running quickly.

This tutorial will help you start using Appwrite products and build your next project. Before starting, make sure you have followed the Appwrite installation guide, and you have an Appwrite server instance up and running on your host machine or server.

Get the Appwrite SDK for Your Platform

We provide libraries and SDKs for major programming languages and platforms so you don't have to write code for interacting with our HTTP APIs from scratch.

Choose your desired SDK corresponding to your product development platform and import it using the given package manager. For the sake of this tutorial we will use code examples using Appwrite SDKs for Node.js, PHP, Python, Ruby, Dart, and Deno, but the same can be applied to any of our server side SDKs.

  • Node.js

    npm install node-appwrite --save
  • PHP

    composer require 'appwrite/appwrite'
  • Python

    pip install appwrite
  • Ruby

    gem install appwrite --save
  • Deno

    import * as sdk from "https://deno.land/x/appwrite/mod.ts";
  • Dart

    dart pub add dart_appwrite
  • Kotlin

    Add maven repositories to your `build.gradle(.kts)` file

    repositories {
        mavenCentral()
    }

    Add Appwrite SDK under dependencies in your `build.gradle(.kts)` file

    dependencies {
        implementation("io.appwrite:sdk-for-kotlin:")
    }

Create Your First Appwrite Project

Go to your new Appwrite console and once inside click the icon in the top navigation header or on the 'Create Project' button on your console homepage. Choose a name for your project and click create to get started.

Authentication

The Appwrite server API provides you with two authentication methods. The first one uses an API key, and the second is using a JSON Web Token (JWT). Each method has different use cases, and you can use whichever fills your app needs.

API Key

Using an API Key you can interact with the Appwrite server API as an admin. You'll be able to access all of your project resources as long as your key has the relevant access scopes attached. To get your first API key, go to your appwrite console, choose the project you created in the step before and click the 'API Keys' link.

Once inside your API keys screen, click the 'Add API Key' button, choose your key name, for example: 'Demo Key', and select the scopes your key will be granted to use. Once completed, you could copy your new API Key and use it to initialize your Appwrite server SDK. To learn about the different API scopes available to you, read more about Appwrite API Keys

  • Node.js

    const sdk = require('node-appwrite');
    
    const client = new sdk.Client();
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
  • PHP

    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
  • Python

    from appwrite.client import Client
    from appwrite.services.users import Users
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
  • Ruby

    require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
  • Deno

    const client = new sdk.Client();
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
  • Dart

    import 'package:dart_appwrite/dart_appwrite.dart';
    
    Client client = Client();
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
  • Kotlin

    import io.appwrite.Client
    
    val client = Client()
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key

A Note About API Keys & Admin Mode

When using Appwrite API from your server-side with an API Key you will automatically run in admin mode. Admin mode disables the default user permission access control restrictions and allows you to access all the resources available on your project. This is very useful when you want to manipulate your users' data like files and documents or even if you want to get a list of your users.

Please note it is highly not recommended to run the admin mode from your client-side as it will probably lead to huge privacy and security issues. Check the Admin Mode documentation to learn more

JSON Web Token (JWT)  version >= 0.8

Using a JSON Web Token (JWT), you can interact with the Appwrite server API as a specific user. You'll be able to access only the relevant user resources and perform actions on his behalf.

To create a JWT, you need to use the "account->createJWT" method using one of the Appwrite client SDKs. Before creating a token, you need to make sure your user is authenticated using the `createSession` method or log in with an OAuth provider.

  • Web SDK

    appwrite // Get a JWT for authenticated user
        .account.createJWT()
                .then(function (response) {
                    console.log(response);
                }, function (error) {
                    console.log(error);
                });
  • Flutter SDK

    Account account = Account(client);
    
    Response user = await account
        .createJWT();
  • Android SDK

    val account = Account(client)
    
    val response = account
        .createJWT()

Once you get your valid token, you can pass it to your server and use it to initialize your Appwrite Server SDK and start making API calls. Your JWT will be valid for a maximum time of 15 minutes or less if the user session has expired before that time.

  • Node.js

    const sdk = require('node-appwrite');
    
    const client = new sdk.Client();
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setJWT('919c2d18fb5d4...a2ae413da83346ad2') // Your secret JWT
    ;
  • PHP

    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setJWT('919c2d18fb5d4...a2ae413da83346ad2') // Your secret JWT
    ;
  • Python

    from appwrite.client import Client
    from appwrite.services.users import Users
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_jwt('919c2d18fb5d4...a2ae413da83346ad2') # Your secret JWT
    )
  • Ruby

    require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_jwt('919c2d18fb5d4...a2ae413da83346ad2') # Your secret JWT
    ;
  • Deno

    const client = new sdk.Client();
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setJWT('919c2d18fb5d4...a2ae413da83346ad2') // Your secret JWT
    ;
  • Dart

    import 'package:dart_appwrite/dart_appwrite.dart';
    
    Client client = Client();
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setJWT('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
  • Kotlin

    import io.appwrite.Client
    
    val client = Client()
    client
        .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
        .setProject("5df5acd0d48c2") // Your project ID
        .setJWT("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key

Make Your First Request

Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.

  • Node.js

    const users = new sdk.Users(client);
    
    let promise = users.create('email@example.com', 'password');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • PHP

    $users = new Users($client);
    
    $result = $users->create('email@example.com', 'password');
  • Python

    users = Users(client)
    
    result = users.create('email@example.com', 'password')
  • Ruby

    users = Appwrite::Users.new(client);
    
    response = users.create(email: 'email@example.com', password: 'password');
    
    puts response
  • Deno

    const users = new sdk.Users(client);
    
    let promise = users.create('email@example.com', 'password');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • Dart

    final users = Users(client);
    
    final res = users.create('email@example.com', 'password');
    
    res.then((response) {
        print(response);
    }).catchError((error) {
        print(error);
    });
  • Kotlin

    import io.appwrite.services.Users
    
    val users = Users(client);
    
    val res = users.create(email = 'email@example.com', password = 'password');
    println(res.body?.string())

Full Example

  • Node.js

    const sdk = require('node-appwrite');
    
    const client = new sdk.Client();
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    const users = new sdk.Users(client);
    let promise = users.create('email@example.com', 'password');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • PHP

    use Appwrite\Client;
    use Appwrite\Services\Users;
    
    $client = new Client();
    
    $client
        ->setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        ->setProject('5df5acd0d48c2') // Your project ID
        ->setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    $users = new Users($client);
    
    $result = $users->create('email@example.com', 'password');
  • Python

    from appwrite.client import Client
    from appwrite.services.users import Users
    
    client = Client()
    
    (client
      .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
      .set_project('5df5acd0d48c2') # Your project ID
      .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    )
    
    users = Users(client)
    
    result = users.create('email@example.com', 'password')
  • Ruby

    require 'appwrite'
    
    client = Appwrite::Client.new()
    
    client
        .set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint
        .set_project('5df5acd0d48c2') # Your project ID
        .set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
    ;
    
    users = Appwrite::Users.new(client);
    
    response = users.create(email: 'email@example.com', password: 'password');
    
    puts response
  • Deno

    import * as sdk from "https://deno.land/x/appwrite/mod.ts";
    
    const client = new sdk.Client();
    const users = new sdk.Users(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    let promise = users.create('email@example.com', 'password');
    
    promise.then(function (response) {
        console.log(response);
    }, function (error) {
        console.log(error);
    });
  • Dart

    import 'package:dart_appwrite/dart_appwrite.dart';
    
    final client = Client();
    final users = Users(client);
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    ;
    
    final res = users.create('email@example.com', 'password');
    
    res.then((response) {
        print(response);
    }).catchError((error) {
        print(error);
    });
  • Kotlin

    import io.appwrite.Client
    import io.appwrite.services.Users
    
    val client = Client();
    
    client
        .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
        .setProject('5df5acd0d48c2') // Your project ID
        .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    
    val users = Users(client);
    
    val res = users.create('email@example.com', 'password');
    
    println(res.body?.string())

Next Steps

Appwrite has many services and tools to help improve your app and speed up your development. The best way to learn how you can take advantage of them is to explore the different API references docs.