Skip to content

gewenyu99/sdk-for-cli

 
 

Repository files navigation

Appwrite Command Line SDK

License Version Build Status Twitter Account Discord

This SDK is compatible with Appwrite server version 0.12.x. For older versions, please check previous releases.

Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Command Line SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to https://appwrite.io/docs

Appwrite

Installation

This tutorial assumes that you have docker setup and running on your machine.

You can install the CLI by getting our installation script.

Linux / MacOS

$ wget -q https://appwrite.io/cli/install.sh  -O - | /bin/bash  

Windows

$ iwr -useb https://appwrite.io/cli/install.ps1 | iex

Initialisation

The CLI needs to be initialised with your project settings. This can be done using

$ appwrite init 

The CLI requires an endpoint, project ID, API key and a locale to be able to communicate with the Appwrite backend server. There are two ways to achieve this

1. Pass in the project settings along with appwrite init

$ appwrite init --endpoint="YOUR ENDPOINT" --project="YOUR PROJECT ID" --key="YOUR API KEY" --locale="YOUR LOCALE"

If any of the required values are missing, a prompt will show up, asking for those missing values.

2. Using the prompt

Invoking appwrite init without any params triggers an interactive prompt where you can manually enter the details. These values are saved locally so that you dont have to re-enter them everytime.

Note

By default, requests to domains with self signed SSL certificates (or no certificates) are disabled. If you trust the domain, you can bypass the certificate validation by using

$ appwrite client setSelfSigned --value=true 

Usage

The Appwrite CLI follows the following general syntax.

$ appwrite [SERVICE] [COMMAND] --[OPTIONS]

A few sample commands to get you started

$ appwrite users create --email="[email protected]" --password="very_strong_password"
$ appwrite users list 

To create a Document you can use the following command

$ appwrite database createDocument --collectionId="YOUR COLLECTION ID" --data='A VALID JSON STRING' --read=role:member --read="*" --write=role:guest

Some Gotchas

  • data expects the JSON string to be escaped.
  • If using the wildcard (*) read or write permissions , make sure that it is properly escaped using a \ or by enclosing it in "*" since bash interprets them differently.
  • Some arguments like read and write permissions are expected to be arrays. In the Appwrite CLI, arrays are passed by simply repeating the argument as seen in the createDocument example above.

To get information about the different services available, you can use

$ appwrite help

To get information about a particular service and the commands available in a service you can use

$ appwrite users help
$ appwrite accounts help

To get information about a particular command and the parameters it accepts, you can use

$ appwrite users list --help
$ appwrite account get --help 

Contribution

This library is auto-generated by Appwrite custom SDK Generator. To learn more about how you can help us improve this SDK, please check the contribution guide before sending a pull-request.

To build and test the CLI for development, follow these steps

  1. Clone the SDK Generator
$ git clone https://github.com/appwrite/sdk-generator
  1. Ensure that docker is running locally and then run
$ cd sdk-generator

# Install the composer dependencies
$ docker run --rm --interactive --tty --volume "$(pwd)":/app composer install --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts --prefer-dist

# Generate the SDKs
$ docker run --rm -v $(pwd):/app -w /app php:7.4-cli php example.php
  1. Head over to the generated SDK and build the CLI docker image
$ cd examples/CLI
$ docker build -t appwrite/cli .
  1. Install the CLI

MacOS and Linux

Open install.sh and change this line to APPWRITE_CLI_IMAGE_VERSION=latest and comment these lines.

You can now install the CLI using

$ chmod +x install.sh
$ ./install.sh

Windows

Open install.ps1 and change this line to APPWRITE_CLI_IMAGE_VERSION=latest and comment these lines

You can now install the CLI using

$ ./install.ps1

License

Please see the BSD-3-Clause license file for more information.

About

[READ-ONLY] Official Appwrite CLI >_

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 94.0%
  • Shell 3.6%
  • PowerShell 2.1%
  • Dockerfile 0.3%