### Full SDK Initialization and Registration Example Source: https://github.com/appwrite/sdk-for-web/blob/main/README.md A complete example combining client initialization and user registration. ```javascript // Init your Web SDK const client = new Client(); client .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint .setProject('455x34dfkj') ; const account = new Account(client); // Register User account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien") .then(function (response) { console.log(response); }, function (error) { console.log(error); }); ``` -------------------------------- ### Install Appwrite via NPM Source: https://github.com/appwrite/sdk-for-web/blob/main/README.md Use this command to add the Appwrite package to your project dependencies. ```bash npm install appwrite --save ``` -------------------------------- ### Get Session using SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/get-session.md Use this method to retrieve session details by providing the session ID. Ensure your client is initialized with your project details. ```javascript import { Client, Account } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const account = new Account(client); const result = await account.getSession({ sessionId: '' }); console.log(result); ``` -------------------------------- ### Create TOTP Authenticator Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/create-mfa-authenticator.md This snippet demonstrates how to initiate the creation of a TOTP authenticator for a user. The response will contain details needed to complete the setup, such as a secret key. ```APIDOC ## createMFAAuthenticator ### Description Creates a new MFA authenticator for the user. Currently, only TOTP is supported. ### Method `account.createMFAAuthenticator(authenticatorCreationRequest)` ### Parameters #### Request Body - **type** (string) - Required - The type of the authenticator to create. Use `AuthenticatorType.Totp` for TOTP. ### Request Example ```javascript const result = await account.createMFAAuthenticator({ type: AuthenticatorType.Totp }); ``` ### Response #### Success Response (200) - **$id** (string) - The ID of the authenticator. - **userId** (string) - The ID of the user the authenticator belongs to. - **type** (string) - The type of the authenticator. - **secret** (string) - The secret key for TOTP authenticators, used to generate codes. - **qr** (string) - The QR code string for TOTP authenticators, which can be used to set up authenticator apps. - **name** (string) - The name of the authenticator (e.g., 'Default TOTP'). - **datetimeCreated** (string) - The date and time the authenticator was created. - **datetimeUpdated** (string) - The date and time the authenticator was last updated. #### Response Example ```json { "$id": "60a5f1b2c3d4e5f6a7b8c9d0", "userId": "60a5f1b2c3d4e5f6a7b8c9d1", "type": "totp", "secret": "YOUR_TOTP_SECRET_KEY", "qr": "otpauth://totp/Appwrite:user@example.com?secret=YOUR_TOTP_SECRET_KEY&issuer=Appwrite", "name": "Default TOTP", "datetimeCreated": "2023-10-27T10:00:00.000+00:00", "datetimeUpdated": "2023-10-27T10:00:00.000+00:00" } ``` ``` -------------------------------- ### Get File Preview Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file-preview.md Generates a preview of a file. You can specify various parameters to customize the preview, such as width, height, quality, and output format. ```APIDOC ## Get File Preview ### Description Generates a preview of a file with customizable options. ### Method ```javascript storage.getFilePreview(parameters) ``` ### Parameters #### Path Parameters - **bucketId** (string) - Required - Bucket ID. - **fileId** (string) - Required - File ID. #### Query Parameters - **width** (integer) - Optional - Preview width, in pixels. Default value is 0. - **height** (integer) - Optional - Preview height, in pixels. Default value is 0. - **gravity** (string) - Optional - Image gravity. Default value is `ImageGravity.Center`. - **quality** (integer) - Optional - Preview quality, between 0 and 100. Default value is -1. - **borderWidth** (integer) - Optional - Preview border width, in pixels. Default value is 0. - **borderColor** (string) - Optional - Preview border color. Default value is an empty string. - **borderRadius** (integer) - Optional - Preview border radius, in pixels. Default value is 0. - **opacity** (float) - Optional - Preview opacity, between 0 and 1. Default value is 0. - **rotation** (integer) - Optional - Preview rotation in degrees. Default value is -360. - **background** (string) - Optional - Preview background color. Default value is an empty string. - **output** (string) - Optional - Preview output format. Default value is `ImageFormat.Jpg`. - **token** (string) - Optional - Security token. Default value is an empty string. ### Request Example ```javascript const result = await storage.getFilePreview({ bucketId: '', fileId: '', width: 800, height: 600, quality: 80, output: ImageFormat.Png }); ``` ### Response #### Success Response (200) - **data** (string) - The file preview data as a string (e.g., base64 encoded). #### Response Example ```json { "data": "" } ``` ``` -------------------------------- ### Get Presence with Appwrite Web SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/presences/get.md Initializes the Appwrite client and retrieves a specific presence by its ID. Ensure the endpoint and project ID are correctly configured. ```javascript import { Client, Presences } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const presences = new Presences(client); const result = await presences.get({ presenceId: '' }); console.log(result); ``` -------------------------------- ### Disable MFA Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/update-mfa.md This example demonstrates how to disable Multi-Factor Authentication for the current user account. ```APIDOC ## Disable MFA ### Description Disables Multi-Factor Authentication for the current user. ### Method `account.updateMFA` ### Parameters #### Request Body - **mfa** (boolean) - Required - Set to `false` to disable MFA. ### Request Example ```json { "mfa": false } ``` ### Response #### Success Response (200) Returns the updated user object. #### Response Example ```json { "$id": "60a9b0f1e1f1f1f1f1f1f1f1", "name": "John Doe", "email": "john.doe@example.com", "registration": "2023-01-01T12:00:00.000+00:00", "prefs": {}, "mfa": false, "mfaLevel": "none" } ``` ``` -------------------------------- ### Get Image Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/avatars/get-image.md Retrieves an image from a given URL. You can optionally specify the width and height for resizing. ```APIDOC ## GET /avatars/image ### Description Retrieves an image from a given URL. You can optionally specify the width and height for resizing. ### Method GET ### Endpoint /avatars/image ### Parameters #### Query Parameters - **url** (string) - Required - The URL of the image to retrieve. - **width** (integer) - Optional - The desired width of the image. - **height** (integer) - Optional - The desired height of the image. ### Response #### Success Response (200) - **image** (string) - The image data in base64 format. ``` -------------------------------- ### Create Row Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/tablesdb/create-row.md This example demonstrates how to create a new row in a specified table within a database. It includes setting the database ID, table ID, a unique row ID, the data for the row, and optional permissions and transaction ID. ```APIDOC ## Create Row ### Description Creates a new row in a specified table within a database. ### Method `tablesDB.createRow(attributes)` ### Parameters #### Path Parameters - **databaseId** (string) - Required - The ID of the database. - **tableId** (string) - Required - The ID of the table. - **rowId** (string) - Required - The ID of the row to create. Use `ID.unique()` for auto-generation. #### Request Body - **data** (object) - Required - An object containing the key-value pairs for the row's attributes. - **permissions** (array) - Optional - An array of permission objects to set for the row. - **transactionId** (string) - Optional - The ID of the transaction to associate with this operation. ``` -------------------------------- ### Get a File - Appwrite SDK for Web Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file.md Use this snippet to retrieve a file from your Appwrite storage. Ensure you have initialized the Appwrite client and Storage service with your project details. ```javascript import { Client, Storage } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const storage = new Storage(client); const result = await storage.getFile({ bucketId: '', fileId: '' }); console.log(result); ``` -------------------------------- ### Get File Download using Appwrite Web SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file-download.md Use this snippet to initiate a file download from Appwrite Storage. Ensure you have initialized the Appwrite client and storage service. The token parameter is optional and can be used for authenticated downloads. ```javascript import { Client, Storage } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const storage = new Storage(client); const result = storage.getFileDownload({ bucketId: '', fileId: '', token: '' // optional }); console.log(result); ``` -------------------------------- ### Get Document by ID - JavaScript Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/databases/get-document.md Use the `getDocument` method to retrieve a document by its unique ID. Ensure your client is initialized with your project details. ```javascript import { Client, Databases } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const databases = new Databases(client); const result = await databases.getDocument({ databaseId: '', collectionId: '', documentId: '', queries: [], // optional transactionId: '' // optional }); console.log(result); ``` -------------------------------- ### Get User Preferences - Web SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/get-prefs.md Retrieve the current user's preferences. Ensure you have initialized the Appwrite client with your project details and endpoint. ```javascript import { Client, Account } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const account = new Account(client); const result = await account.getPrefs(); console.log(result); ``` -------------------------------- ### Get File Preview with Appwrite SDK for Web Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file-preview.md Use this snippet to generate a preview of a file stored in Appwrite. You can specify dimensions, quality, format, and other options to customize the preview. Ensure you have initialized the Appwrite client with your endpoint and project ID. ```javascript import { Client, Storage, ImageGravity, ImageFormat } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const storage = new Storage(client); const result = storage.getFilePreview({ bucketId: '', fileId: '', width: 0, // optional height: 0, // optional gravity: ImageGravity.Center, // optional quality: -1, // optional borderWidth: 0, // optional borderColor: '', // optional borderRadius: 0, // optional opacity: 0, // optional rotation: -360, // optional background: '', // optional output: ImageFormat.Jpg, // optional token: '' // optional }); console.log(result); ``` -------------------------------- ### Get Function Execution Details Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/functions/get-execution.md Use this snippet to retrieve the details of a specific function execution. Ensure you have initialized the Appwrite client and Functions service with your project details. ```javascript import { Client, Functions } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const functions = new Functions(client); const result = await functions.getExecution({ functionId: '', executionId: '' }); console.log(result); ``` -------------------------------- ### Get Locale Information Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/locale/get.md Use this snippet to retrieve the current locale settings for your project. Ensure your client is properly initialized with your project ID and API endpoint. ```javascript import { Client, Locale } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.get(); console.log(result); ``` -------------------------------- ### Get Team Details Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/teams/get.md Use this snippet to fetch a specific team's details by providing its unique ID. Ensure you have initialized the Appwrite client with your project details. ```javascript import { Client, Teams } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const teams = new Teams(client); const result = await teams.get({ teamId: '' }); console.log(result); ``` -------------------------------- ### Get Team Preferences Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/teams/get-prefs.md Retrieves the preferences object for a team. Use this method to get the current settings and configurations associated with a specific team. ```APIDOC ## GET /teams/{teamId}/prefs ### Description Retrieves the preferences object for a team. ### Method GET ### Endpoint /teams/{teamId}/prefs ### Parameters #### Path Parameters - **teamId** (string) - Required - The ID of the team for which to retrieve preferences. ### Response #### Success Response (200) - **prefs** (object) - An object containing the team's preferences. ### Response Example { "prefs": { "key1": "value1", "key2": "value2" } } ``` -------------------------------- ### Initialize Appwrite Client Source: https://github.com/appwrite/sdk-for-web/blob/main/README.md Configure the SDK with your server endpoint and project ID. ```javascript // Init your Web SDK const client = new Client(); client .setEndpoint('http://localhost/v1') // Your Appwrite Endpoint .setProject('455x34dfkj') // Your project ID ; ``` -------------------------------- ### Register a User Source: https://github.com/appwrite/sdk-for-web/blob/main/README.md Create a new user account using the Account service. ```javascript const account = new Account(client); // Register User account.create(ID.unique(), "email@example.com", "password", "Walter O'Brien") .then(function (response) { console.log(response); }, function (error) { console.log(error); }); ``` -------------------------------- ### Get Image using Avatars Service Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/avatars/get-image.md Use the Avatars service to get an image from a given URL. Optional width and height parameters can be provided to resize the image. ```javascript import { Client, Avatars } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const avatars = new Avatars(client); const result = avatars.getImage({ url: 'https://example.com', width: 0, // optional height: 0 // optional }); console.log(result); ``` -------------------------------- ### Create a new user account Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/create.md Initializes the Appwrite client and uses the account.create method to register a new user. Ensure the endpoint and project ID are correctly configured. ```javascript import { Client, Account } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const account = new Account(client); const result = await account.create({ userId: '', email: 'email@example.com', password: 'password', name: '' // optional }); console.log(result); ``` -------------------------------- ### Get File View - Appwrite SDK for Web Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file-view.md Use this snippet to get a view of a file from your Appwrite storage. Ensure you have initialized the Appwrite client and storage service before calling this function. The token parameter is optional and can be used for temporary access. ```javascript import { Client, Storage } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const storage = new Storage(client); const result = storage.getFileView({ bucketId: '', fileId: '', token: '' // optional }); console.log(result); ``` -------------------------------- ### Create a function execution in JavaScript Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/functions/create-execution.md Initializes the Appwrite client and executes a function using the Functions service. ```javascript import { Client, Functions, ExecutionMethod } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const functions = new Functions(client); const result = await functions.createExecution({ functionId: '', body: '', // optional async: false, // optional xpath: '', // optional method: ExecutionMethod.GET, // optional headers: {}, // optional scheduledAt: '' // optional }); console.log(result); ``` -------------------------------- ### Get Transaction Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/tablesdb/get-transaction.md Fetches a transaction using its unique ID. ```APIDOC ## Get Transaction ### Description Retrieves the details of a specific transaction using its ID. ### Method `getTransaction` ### Parameters #### Input Parameters - **transactionId** (string) - Required - The unique identifier of the transaction to retrieve. ### Request Example ```javascript const result = await tablesDB.getTransaction({ transactionId: '' }); ``` ### Response #### Success Response (200) Returns an object containing the transaction details. #### Response Example ```json { "$id": "60c72b2f96714", "$collectionId": "60c72b2f96714", "$createdAt": "2023-10-27T10:00:00.000+00:00", "$updatedAt": "2023-10-27T10:00:00.000+00:00", "amount": 1000, "currency": "USD", "status": "completed", "description": "Payment for order #123" } ``` ``` -------------------------------- ### List Currencies using Appwrite SDK for Web Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/locale/list-currencies.md Initialize the Appwrite client and use the Locale service to fetch a list of currencies. Ensure you replace placeholders with your actual API endpoint and project ID. ```javascript import { Client, Locale } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listCurrencies(); console.log(result); ``` -------------------------------- ### Get Transaction Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/databases/get-transaction.md Fetches a transaction using its unique ID. ```APIDOC ## Get Transaction ### Description Retrieves a specific transaction by its ID. ### Method `getTransaction` ### Parameters #### Path Parameters - **transactionId** (string) - Required - The ID of the transaction to retrieve. ### Request Example ```javascript const result = await databases.getTransaction({ transactionId: '' }); ``` ### Response #### Success Response (200) - **transaction** (object) - The transaction object. #### Response Example ```json { "$id": "60c72b2f96714", "$collectionId": "60c72b2f96714", "$databaseId": "60c72b2f96714", "amount": 1000, "currency": "USD", "status": "completed", "createdAt": "2023-10-27T10:00:00.000+00:00", "updatedAt": "2023-10-27T10:05:00.000+00:00" } ``` ``` -------------------------------- ### Get Team Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/teams/get.md This snippet shows how to retrieve a team using the `teams.get` method. ```APIDOC ## Get Team ### Description Retrieves a team using its unique ID. ### Method `teams.get(teamId: string)` ### Parameters #### Path Parameters - **teamId** (string) - Required - The unique ID of the team to retrieve. ### Request Example ```javascript const result = await teams.get({ teamId: '' }); ``` ### Response #### Success Response (200) - **$id** (string) - The team's unique ID. - **name** (string) - The team's name. - **createdAt** (string) - The date the team was created. - **updatedAt** (string) - The date the team was last updated. - **membersCount** (integer) - The number of members in the team. - **total** (integer) - The total number of teams available in the response. #### Response Example ```json { "$id": "60a9b0f1b1f1f1f1f1f1f1f1", "name": "Team Alpha", "createdAt": "2023-01-01T12:00:00.000+00:00", "updatedAt": "2023-01-01T12:00:00.000+00:00", "membersCount": 5, "total": 1 } ``` ``` -------------------------------- ### Execute a GraphQL Query Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/graphql/query.md Initialize the Appwrite client and execute a GraphQL query. Ensure you replace placeholders with your actual API endpoint and project ID. ```javascript import { Client, Graphql } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const graphql = new Graphql(client); const result = await graphql.query({ query: {} }); console.log(result); ``` -------------------------------- ### List Transactions using Appwrite SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/databases/list-transactions.md Initialize the Appwrite client and then use the Databases service to list all transactions. Replace placeholders with your actual API endpoint and project ID. ```javascript import { Client, Databases } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const databases = new Databases(client); const result = await databases.listTransactions({ queries: [] // optional }); console.log(result); ``` -------------------------------- ### Get Session Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/get-session.md Retrieves the details of a specific user session using its ID. ```APIDOC ## Get Session ### Description Retrieves the details of a specific user session using its ID. ### Method POST ### Endpoint /account/sessions ### Parameters #### Request Body - **sessionId** (string) - Required - The ID of the session to retrieve. ### Request Example ```json { "sessionId": "" } ``` ### Response #### Success Response (200) - **$id** (string) - The unique identifier for the session. - **userId** (string) - The ID of the user associated with the session. - **provider** (string) - The authentication provider used for the session (e.g., 'email', 'google'). - **providerUid** (string) - The unique identifier from the provider. - **providerAccessToken** (string) - The access token from the provider. - **providerAccessTokenExpiry** (string) - The expiration time of the provider access token. - **providerRefreshToken** (string) - The refresh token from the provider. - **userAgent** (string) - The user agent string of the device that created the session. - **ip** (string) - The IP address from which the session was created. - **osName** (string) - The name of the operating system. - **osVersion** (string) - The version of the operating system. - **clientName** (string) - The name of the client (e.g., 'Chrome', 'Firefox'). - **clientVersion** (string) - The version of the client. - **clientEngine** (string) - The rendering engine of the client (e.g., 'Blink', 'Gecko'). - **clientEngineVersion** (string) - The version of the client engine. - **deviceName** (string) - The name of the device. - **deviceBrand** (string) - The brand of the device. - **deviceFamily** (string) - The family of the device. - **countryCode** (string) - The ISO 3166-1 alpha-2 country code. - **country** (string) - The name of the country. - **region** (string) - The name of the region. - **city** (string) - The name of the city. - **createdAt** (string) - The date and time the session was created. #### Response Example ```json { "$id": "63a7c1f7d4b1e3a7f0f0", "userId": "63a7c1f7d4b1e3a7f0f0", "provider": "email", "providerUid": "", "providerAccessToken": "", "providerAccessTokenExpiry": "", "providerRefreshToken": "", "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", "ip": "127.0.0.1", "osName": "Windows", "osVersion": "10", "clientName": "Chrome", "clientVersion": "108.0.0.0", "clientEngine": "Blink", "clientEngineVersion": "108.0.0.0", "deviceName": "Desktop", "deviceBrand": "Other", "deviceFamily": "Other", "countryCode": "US", "country": "United States", "region": "California", "city": "San Francisco", "createdAt": "2023-01-01T12:00:00.000+00:00" } ``` ``` -------------------------------- ### List Files in a Bucket - Web SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/list-files.md Use this snippet to list files in a specific bucket. Ensure you have initialized the Appwrite client and storage service. Optional parameters like queries, search, and total count can be provided. ```javascript import { Client, Storage } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const storage = new Storage(client); const result = await storage.listFiles({ bucketId: '', queries: [], // optional search: '', // optional total: false // optional }); console.log(result); ``` -------------------------------- ### List Account Logs Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/list-logs.md Use the `listLogs` method to retrieve account logs. Ensure you have initialized the Appwrite client with your endpoint and project ID. The `queries` and `total` parameters are optional. ```javascript import { Client, Account } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const account = new Account(client); const result = await account.listLogs({ queries: [], // optional total: false // optional }); console.log(result); ``` -------------------------------- ### Get User Preferences Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/get-prefs.md Fetches the current user's preferences. This method does not require any parameters. ```APIDOC ## GET /account/prefs ### Description Retrieves the user's preferences. ### Method GET ### Endpoint /account/prefs ### Response #### Success Response (200) - **prefs** (object) - User preferences object. ### Response Example ```json { "prefs": { "exampleKey": "exampleValue" } } ``` ``` -------------------------------- ### Get Browser Icon Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/avatars/get-browser.md Retrieves the URL of a browser icon. You can specify the icon code, dimensions, and quality. ```APIDOC ## GET /avatars/browser ### Description Retrieves the URL of a browser icon. You can specify the icon code, dimensions, and quality. ### Method GET ### Endpoint /avatars/browser ### Parameters #### Query Parameters - **code** (string) - Required - Browser code. Use one of the constants from `Browser` class, e.g. `Browser.AvantBrowser`. - **width** (integer) - Optional - Width of the image in pixels. Defaults to 100. - **height** (integer) - Optional - Height of the image in pixels. Defaults to 100. - **quality** (integer) - Optional - Quality of the image. Defaults to 100. Minimum is 0, maximum is 100. ### Response #### Success Response (200) - **url** (string) - URL of the browser icon. ``` -------------------------------- ### Get Account Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/account/get.md Retrieves the current user's account information. This method requires the user to be authenticated. ```APIDOC ## Get Account ### Description Retrieves the current user's account information. This method requires the user to be authenticated. ### Method GET ### Endpoint /account ### Parameters This endpoint does not accept any parameters. ### Request Example ```javascript const result = await account.get(); console.log(result); ``` ### Response #### Success Response (200) - **$id** (string) - The unique identifier for the user account. - **name** (string) - The name of the user. - **email** (string) - The email address of the user. - **registration** (string) - The date and time the user registered. - **prefs** (object) - User preferences. #### Response Example ```json { "$id": "60a9b1b3b3b3b3b3b3b3b3b3", "name": "John Doe", "email": "john.doe@example.com", "registration": "2023-01-01T12:00:00.000+00:00", "prefs": {} } ``` ``` -------------------------------- ### Create Team using Appwrite SDK for Web Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/teams/create.md Use this snippet to create a new team. Ensure you have initialized the Appwrite client with your endpoint and project ID. ```javascript import { Client, Teams } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const teams = new Teams(client); const result = await teams.create({ teamId: '', name: '', roles: [] // optional }); console.log(result); ``` -------------------------------- ### Create File Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/create-file.md This snippet demonstrates how to create a new file in a specified bucket. You need to provide the bucket ID, a unique file ID, the file object itself (typically from an input element), and optionally, permissions. ```APIDOC ## createFile ### Description Creates a new file in a specified bucket. This operation allows you to upload files to your Appwrite project's storage. ### Method `storage.createFile(options)` ### Parameters #### Request Body - **bucketId** (string) - Required - The ID of the bucket where the file will be uploaded. - **fileId** (string) - Required - The unique ID to assign to the file. Use `unique()` for auto-generated IDs. - **file** (File) - Required - The file object to upload. This is typically obtained from an HTML file input element. - **permissions** (Array) - Optional - An array of permissions to assign to the file. Defaults to read access for all users if not provided. ### Request Example ```javascript const result = await storage.createFile({ bucketId: '', fileId: '', // or 'unique()' file: document.getElementById('uploader').files[0], permissions: [Permission.read(Role.any())] // optional }); ``` ### Response #### Success Response (200) Returns an object describing the created file, including its ID, name, size, creation date, and associated permissions. - **$id** (string) - The unique ID of the file. - **name** (string) - The name of the file. - **size** (integer) - The size of the file in bytes. - **createdAt** (string) - The date and time the file was created. - **permissions** (Array) - The permissions associated with the file. #### Response Example ```json { "$id": "60c72b2f9671f", "name": "my-document.pdf", "size": 1024, "createdAt": "2023-10-27T10:00:00.000+00:00", "permissions": [ "read(role:any)" ] } ``` ``` -------------------------------- ### Get File View Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file-view.md Retrieves a file from storage. The file is returned as a viewable resource (e.g., an image, document). ```APIDOC ## getFileView ### Description Retrieves a file from storage. The file is returned as a viewable resource (e.g., an image, document). ### Method `storage.getFileView({bucketId, fileId, token})` ### Parameters #### Path Parameters - **bucketId** (string) - Required - The ID of the bucket where the file is stored. - **fileId** (string) - Required - The ID of the file to retrieve. - **token** (string) - Optional - An optional security token for accessing the file. ``` -------------------------------- ### Get File Download Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/get-file-download.md Downloads a file from a specific bucket. The token parameter is optional and can be used for temporary access. ```APIDOC ## Get File Download ### Description Downloads a file from a specific bucket. The token parameter is optional and can be used for temporary access. ### Method GET ### Endpoint /storage/files/{fileId}/download ### Parameters #### Path Parameters - **bucketId** (string) - Required - The ID of the bucket where the file is stored. - **fileId** (string) - Required - The ID of the file to download. #### Query Parameters - **token** (string) - Optional - A token for temporary access to the file. ### Response #### Success Response (200) - **file** (blob) - The downloaded file content. ### Request Example ```javascript const result = await storage.getFileDownload( '', '', '' ); ``` ### Response Example ```json // The response will be the file content directly (e.g., an image, document, etc.) ``` ``` -------------------------------- ### Capture a website screenshot using the Avatars service Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/avatars/get-screenshot.md Initializes the Appwrite client and calls getScreenshot with optional parameters like viewport dimensions, theme, and geolocation settings. ```javascript import { Client, Avatars, BrowserTheme, Timezone, BrowserPermission, ImageFormat } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const avatars = new Avatars(client); const result = avatars.getScreenshot({ url: 'https://example.com', headers: { "Authorization": "Bearer token123", "X-Custom-Header": "value" }, // optional viewportWidth: 1920, // optional viewportHeight: 1080, // optional scale: 2, // optional theme: BrowserTheme.Dark, // optional userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15', // optional fullpage: true, // optional locale: 'en-US', // optional timezone: Timezone.AfricaAbidjan, // optional latitude: 37.7749, // optional longitude: -122.4194, // optional accuracy: 100, // optional touch: true, // optional permissions: [BrowserPermission.Geolocation, BrowserPermission.Notifications], // optional sleep: 3, // optional width: 800, // optional height: 600, // optional quality: 85, // optional output: ImageFormat.Jpeg // optional }); console.log(result); ``` -------------------------------- ### Get Team Membership Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/teams/get-membership.md Retrieves the details of a specific membership within a team. Requires the team ID and the membership ID. ```APIDOC ## Get Team Membership ### Description Retrieves the details of a specific membership within a team. Requires the team ID and the membership ID. ### Method `teams.getMembership({ teamId, membershipId })` ### Parameters #### Path Parameters - **teamId** (string) - Required - The ID of the team. - **membershipId** (string) - Required - The ID of the membership. ### Request Example ```javascript const result = await teams.getMembership({ teamId: '', membershipId: '' }); ``` ### Response #### Success Response (200) - **_id** (string) - The ID of the membership. - **teamId** (string) - The ID of the team. - **userId** (string) - The ID of the user. - **name** (string) - The name of the user. - **email** (string) - The email of the user. - **role** (string) - The role of the user in the team. - **joined** (integer) - The timestamp when the user joined the team. #### Response Example ```json { "_id": "60c72b2f96714", "teamId": "60c72b2f96714", "userId": "60c72b2f96714", "name": "John Doe", "email": "john.doe@example.com", "role": "member", "joined": 1623540000 } ``` ``` -------------------------------- ### Create File with Permissions - Web SDK Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/storage/create-file.md Use this snippet to upload a file to a specified bucket with custom read permissions. Ensure the client is initialized with your project details and the file is selected via an input element. ```javascript import { Client, Storage, Permission, Role } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const storage = new Storage(client); const result = await storage.createFile({ bucketId: '', fileId: '', file: document.getElementById('uploader').files[0], permissions: [Permission.read(Role.any())] // optional }); console.log(result); ``` -------------------------------- ### Get Transaction by ID Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/tablesdb/get-transaction.md Use this snippet to retrieve a transaction by its ID. Ensure you have initialized the Appwrite client and TablesDB service. ```javascript import { Client, TablesDB } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const tablesDB = new TablesDB(client); const result = await tablesDB.getTransaction({ transactionId: '' }); console.log(result); ``` -------------------------------- ### Get Locale Information Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/locale/get.md Retrieves the current locale information for the project. This includes the default locale, locales available, and other locale-related settings. ```APIDOC ## GET /locale ### Description Retrieves the current locale information for the project. ### Method GET ### Endpoint /locale ### Parameters None ### Request Example None ### Response #### Success Response (200) - **default** (string) - The default locale code. - **localeCodes** (array) - An array of available locale codes. #### Response Example { "default": "en", "localeCodes": [ "en", "fr", "es" ] } ``` -------------------------------- ### List Documents in a Collection Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/databases/list-documents.md Use this snippet to fetch all documents from a specified collection. Ensure you have initialized the Appwrite client and Databases service with your project details. ```javascript import { Client, Databases } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const databases = new Databases(client); const result = await databases.listDocuments({ databaseId: '', collectionId: '', queries: [], // optional transactionId: '', // optional total: false, // optional ttl: 0 // optional }); console.log(result); ``` -------------------------------- ### Get Document Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/databases/get-document.md Fetches a document by its ID from a specified collection and database. Optional parameters like queries and transaction ID can be provided. ```APIDOC ## getDocument ### Description Retrieves a specific document from a collection. ### Method `databases.getDocument(databaseId, collectionId, documentId, queries?, transactionId?) ### Parameters #### Path Parameters - **databaseId** (string) - Required - The ID of the database. - **collectionId** (string) - Required - The ID of the collection. - **documentId** (string) - Required - The ID of the document to retrieve. #### Optional Parameters - **queries** (Array) - Optional - An array of query strings to filter or order the results. - **transactionId** (string) - Optional - The ID of the transaction to associate with this operation. ### Request Example ```javascript const result = await databases.getDocument({ databaseId: '', collectionId: '', documentId: '', queries: [], // optional transactionId: '' // optional }); ``` ### Response #### Success Response (200) - **document** (object) - The retrieved document object. #### Response Example ```json { "$id": "", "$collectionId": "", "$databaseId": "", "$createdAt": "", "$updatedAt": "", // ... other document fields } ``` ``` -------------------------------- ### List Teams - Appwrite SDK for Web Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/teams/list.md Initialize the Appwrite client and use the Teams service to list all teams. You can optionally provide search parameters or disable total count. Ensure your API endpoint and project ID are correctly configured. ```javascript import { Client, Teams } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const teams = new Teams(client); const result = await teams.list({ queries: [], // optional search: '', // optional total: false // optional }); console.log(result); ``` -------------------------------- ### Get Transaction Details Source: https://github.com/appwrite/sdk-for-web/blob/main/docs/examples/databases/get-transaction.md Use this snippet to retrieve a specific transaction by its ID. Ensure you have initialized the Appwrite client and Databases service. ```javascript import { Client, Databases } from "appwrite"; const client = new Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint .setProject(''); // Your project ID const databases = new Databases(client); const result = await databases.getTransaction({ transactionId: '' }); console.log(result); ```