This SDK targets Appwrite server version 2.5.x as shipped on Appwrite Cloud. Self-hosted releases can lag behind Cloud — if you run an older self-hosted build, use a matching older SDK from previous releases when APIs differ.
Appwrite is an open-source backend as a service server that abstracts and simplifies 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 Go 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
Add the SDK to your Go module:
go get github.com/appwrite/sdk-for-go/v7If you don't have a module yet, create one first with go mod init <YOUR_MODULE_NAME>.
Create a client with your Appwrite API endpoint, project ID and an API key. You can find the project ID in your project settings, and create an API key with the scopes you need in your project's API keys section.
client := appwrite.NewClient(
appwrite.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1"),
appwrite.WithProject("<YOUR_PROJECT_ID>"),
appwrite.WithKey("<YOUR_API_KEY>"),
)If you self-host Appwrite, use your own endpoint, such as https://<HOSTNAME_OR_IP>/v1. Add appwrite.WithSelfSigned(true) only in development, when your server uses a self-signed certificate.
Create a service from the client and call any of its methods. Required parameters are positional; optional parameters are passed with the service's With<Method><Param> options.
package main
import (
"fmt"
"log"
"github.com/appwrite/sdk-for-go/v7/appwrite"
"github.com/appwrite/sdk-for-go/v7/id"
)
func main() {
client := appwrite.NewClient(
appwrite.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1"),
appwrite.WithProject("<YOUR_PROJECT_ID>"),
appwrite.WithKey("<YOUR_API_KEY>"),
)
users := appwrite.NewUsers(client)
user, err := users.Create(
id.Unique(),
users.WithCreateEmail("email@example.com"),
users.WithCreatePassword("password"),
users.WithCreateName("Walter O'Brien"),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(user.Id, user.Name, user.Email)
}Failed requests return a *client.AppwriteError with the HTTP status code, the error message and the raw response body. Use errors.As to read them.
package main
import (
"errors"
"fmt"
"log"
"github.com/appwrite/sdk-for-go/v7/appwrite"
"github.com/appwrite/sdk-for-go/v7/client"
"github.com/appwrite/sdk-for-go/v7/id"
)
func main() {
users := appwrite.NewUsers(appwrite.NewClient(
appwrite.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1"),
appwrite.WithProject("<YOUR_PROJECT_ID>"),
appwrite.WithKey("<YOUR_API_KEY>"),
))
user, err := users.Create(id.Unique(), users.WithCreateEmail("email@example.com"))
if err != nil {
var appwriteError *client.AppwriteError
if errors.As(err, &appwriteError) {
log.Fatalf("Appwrite error %d: %s", appwriteError.GetStatusCode(), appwriteError.GetMessage())
}
log.Fatal(err)
}
fmt.Println(user.Name)
}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.
Please see the BSD-3-Clause license file for more information.
