|
| 1 | +<p>The <a href="https://github.com/appwrite/sdk-for-cli" target="_blank" rel="noopener">Appwrite CLI</a> is a command-line application that allows you to interact with the <a href="/docs/getting-started-for-server">Appwrite server-side APIs</a> and perform server-side tasks quickly using your terminal. A few examples of these tasks including managing resources (documents, files, users), executing and packaging Cloud Functions, and any other operation available through the Appwrite API.</p> |
| 2 | + |
| 3 | +<h2>Getting started</h2> |
| 4 | + |
| 5 | +<p>The Appwrite CLI installation is extremely easy and fast. The CLI is packaged as a Docker container, which makes it secure by default, requires no dependencies but <a href="https://docs.docker.com/get-docker/">Docker</a>, and truly platform and language agnostic.</p> |
| 6 | + |
| 7 | +<p>The next step is to have your Appwrite server running. You can grab our simple <a href="/docs/installation">installation command</a> and execute it.</p> |
| 8 | + |
| 9 | +<p>Next, head over to <a href="http://localhost" rel="noopener" target="_blank">http://localhost</a> and create a project in the Appwrite Console, create an <a href="/docs/keys">API key</a>, and we're good to play around with the CLI.</p> |
| 10 | + |
| 11 | +<h3>Installation</h3> |
| 12 | + |
| 13 | +<p>To install the CLI, we recommend running the installation script for your operating system.</p> |
| 14 | + |
| 15 | +<ul class="phases clear" data-ui-phases> |
| 16 | + <li> |
| 17 | + <h4>MacOS</h4> |
| 18 | + |
| 19 | + <div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash"> |
| 20 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>curl -sL <?php echo $this->getParam('home'); ?>/cli/install.sh | bash</code></pre> |
| 21 | + </div> |
| 22 | + </li> |
| 23 | + <li> |
| 24 | + <h4>Windows</h4> |
| 25 | + |
| 26 | + <div class="ide margin-bottom" data-lang="powershell" data-lang-label="PowerShell"> |
| 27 | + <pre class="line-numbers"><code class="prism language-powershell" data-prism>iwr -useb <?php echo $this->getParam('home'); ?>/cli/install.ps1 | iex</code></pre> |
| 28 | + </div> |
| 29 | + </li> |
| 30 | + <li> |
| 31 | + <h4>Linux</h4> |
| 32 | + |
| 33 | + <div class="ide margin-bottom" data-lang="bash" data-lang-label="Bash"> |
| 34 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>curl -sL <?php echo $this->getParam('home'); ?>/cli/install.sh | bash</code></pre> |
| 35 | + </div> |
| 36 | + </li> |
| 37 | +</ul> |
| 38 | + |
| 39 | +<p>Once the setup is complete, you can validate your installation using:</p> |
| 40 | + |
| 41 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 42 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite version</code></pre> |
| 43 | +</div> |
| 44 | + |
| 45 | +<p>To start using the CLI with your project, you will first need to initialize the CLI with:</p> |
| 46 | + |
| 47 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 48 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite init</code></pre> |
| 49 | +</div> |
| 50 | + |
| 51 | +<p>Great! Now you're all set to use the Appwrite CLI. You can access your CLI using the following general syntax:</p> |
| 52 | + |
| 53 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 54 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite [SERVICE] [COMMAND] --[OPTIONS]</code></pre> |
| 55 | +</div> |
| 56 | + |
| 57 | +<h3>Examples</h3> |
| 58 | + |
| 59 | +<p><b>Create User</b></p> |
| 60 | + |
| 61 | +<p>To create a new user in your project, you can use the `create` command. To successfully create a user, make sure your API key is granted with the scope "users.write".</p> |
| 62 | + |
| 63 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 64 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite users create --email=" [email protected]" --password="my-secret"</code></pre> |
| 65 | +</div> |
| 66 | +<!-- Attach image of output --> |
| 67 | + |
| 68 | +<p><b>List Users</b></p> |
| 69 | + |
| 70 | +<p>To get a list of all your project users, you can use the `list` command. To successfully view the list, make sure your API key is granted with the scope "users.read".</p> |
| 71 | + |
| 72 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 73 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite users list</code></pre> |
| 74 | +</div> |
| 75 | +<!-- Attach image of output --> |
| 76 | + |
| 77 | +<p><b>List Collections</b></p> |
| 78 | + |
| 79 | +<p>To get a list of all your collections, you can use the `listCollections` command. To successfully view the list, make sure your API key is granted with the scope "collections.read".</p> |
| 80 | + |
| 81 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 82 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite database listCollections</code></pre> |
| 83 | +</div> |
| 84 | +<!-- Attach image of output --> |
| 85 | + |
| 86 | +<p><b>Read Collection</b></p> |
| 87 | + |
| 88 | +<p>To get more information on a particular collection, you can make use of the `getCollection` command and pass in the `collectionId`. To successfully fetch the collection, make sure your API key is granted with the scope "collections.read".</p> |
| 89 | + |
| 90 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 91 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite database getCollection --collectionId=5ff468cfa32a0</code></pre> |
| 92 | +</div> |
| 93 | +<!-- Attach image of output --> |
| 94 | + |
| 95 | +<h3>Configuration</h3> |
| 96 | + |
| 97 | +<p>At any point, if you would like to change your project endpoint, project ID, project Key, or locale configuration you set during the CLI init, you can make use of the `client` service.</p> |
| 98 | + |
| 99 | +<div class="ide margin-bottom" data-lang="bash" data-lang-label="CLI"> |
| 100 | + <pre class="line-numbers"><code class="prism language-bash" data-prism>appwrite client setEndpoint --endpoint="http://192.168.1.6/v1" |
| 101 | +appwrite client setProject --project="5ff450422d42f" |
| 102 | +appwrite client setKey --key="23f24gwrhSDgefaY" |
| 103 | +appwrite client setLocale --locale="en-US"</code></pre> |
| 104 | +</div> |
| 105 | + |
| 106 | +<h3>Help</h3> |
| 107 | + |
| 108 | +<p>If you get stuck anywhere, you can always use the `help` command to get the usage examples. All the examples are also available on the Appwrite API specs docs, and you can view them by switching the examples to the "Appwrite CLI" from the top dropdown.</p> |
0 commit comments