### Install Anytype-Go SDK Source: https://github.com/epheo/anytype-go/blob/main/README.md Use 'go get' to install the Anytype-Go SDK. This command fetches and installs the specified package. ```bash go get github.com/epheo/anytype-go ``` -------------------------------- ### Install Anytype Go SDK Source: https://context7.com/epheo/anytype-go/llms.txt Install the SDK using go get. Ensure you also import the client implementation package. ```go go get github.com/epheo/anytype-go ``` ```go import ( "github.com/epheo/anytype-go" _ "github.com/epheo/anytype-go/client" // Register client implementation ) ``` -------------------------------- ### Get Object in Markdown Format Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve a specific object, requesting its content in Markdown format. ```go markdown, _ := client.Space(spaceID).Object(objectID).Get(ctx, anytype.WithFormat("md")) ``` -------------------------------- ### Authenticate with Anytype API Source: https://github.com/epheo/anytype-go/blob/main/README.md This code demonstrates the authentication flow: initiating a challenge, getting user input for the verification code, and exchanging it for an API key to create an authenticated client. ```go client := anytype.NewClient( anytype.WithBaseURL("http://localhost:31009"), ) // Initiate challenge — Anytype app will display a verification code auth, _ := client.Auth().CreateChallenge(ctx, "MyApp") // User enters the code var code string fmt.Scanln(&code) // Exchange for API key token, _ := client.Auth().CreateApiKey(ctx, auth.ChallengeID, code) // Create authenticated client client = anytype.NewClient( anytype.WithBaseURL("http://localhost:31009"), anytype.WithAppKey(token.ApiKey), ) ``` -------------------------------- ### Get Space Details Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve detailed information for a specific space using its unique ID. ```go spaceDetails, err := client.Space("space-id-here").Get(ctx) if err != nil { panic(err) } fmt.Printf("Name: %s\n", spaceDetails.Space.Name) fmt.Printf("Description: %s\n", spaceDetails.Space.Description) fmt.Printf("Network ID: %s\n", spaceDetails.Space.NetworkID) ``` -------------------------------- ### Get SDK Version Information in Go Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve the current SDK version and the compatible API version. This is useful for ensuring compatibility between the SDK and the Anytype API. ```go versionInfo := anytype.GetVersionInfo() fmt.Printf("SDK Version: %s\n", versionInfo.Version) // e.g., "0.53.1" fmt.Printf("API Version: %s\n", versionInfo.APIVersion) // e.g., "2025-11-08" ``` -------------------------------- ### Get a Specific Space Source: https://github.com/epheo/anytype-go/blob/main/README.md Fetch details for a single space using its unique identifier. ```go space, _ := client.Space(spaceID).Get(ctx) ``` -------------------------------- ### Get Property Details Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve detailed information about an existing property using its ID. This is useful for inspecting property configurations. ```go propDetails, err := client.Space(spaceID).Property(propertyID).Get(ctx) if err != nil { panic(err) } fmt.Printf("Property: %s ", propDetails.Property.Name) fmt.Printf("Format: %s ", propDetails.Property.Format) fmt.Printf("Key: %s ", propDetails.Property.Key) ``` -------------------------------- ### Get Template Details in Go Source: https://context7.com/epheo/anytype-go/llms.txt Fetch detailed information for a specific template using its ID. This provides access to the template's layout and other metadata. ```go templateDetails, err := client.Space(spaceID).Type("page").Template(templateID).Get(ctx) if err != nil { panic(err) } fmt.Printf("Template: %s\n", templateDetails.Template.Name) fmt.Printf("Layout: %s\n", templateDetails.Template.Layout) ``` -------------------------------- ### Get a Specific Object Source: https://github.com/epheo/anytype-go/blob/main/README.md Fetch a specific object by its ID within a given space. ```go object, _ := client.Space(spaceID).Object(objectID).Get(ctx) ``` -------------------------------- ### Get Member Details Source: https://context7.com/epheo/anytype-go/llms.txt Fetch detailed information about a specific member within a space. This includes their global name, identity, role, and status. ```go memberDetails, err := client.Space(spaceID).Member(memberID).Get(ctx) if err != nil { panic(err) } fmt.Printf("Name: %s ", memberDetails.Member.Name) fmt.Printf("Global Name: %s ", memberDetails.Member.GlobalName) fmt.Printf("Identity: %s ", memberDetails.Member.Identity) fmt.Printf("Role: %s ", memberDetails.Member.Role) fmt.Printf("Status: %s ", memberDetails.Member.Status) ``` -------------------------------- ### Get Tag Details Source: https://context7.com/epheo/anytype-go/llms.txt Fetch detailed information for a specific tag associated with a property. Requires the property ID and tag ID. ```go tagDetails, err := client.Space(spaceID).Property(propertyID).Tag(tagID).Get(ctx) if err != nil { panic(err) } fmt.Printf("Tag: %s (Color: %s) ", tagDetails.Tag.Name, tagDetails.Tag.Color) ``` -------------------------------- ### Get a Specific Object Type by Key Source: https://context7.com/epheo/anytype-go/llms.txt Fetch the details of a single object type using its unique key. This provides information about the type's name, layout, and associated properties. ```go pageType, err := client.Space(spaceID).Types().Get(ctx, "page") if err != nil { panic(err) } fmt.Printf("Type: %s (ID: %s)\n", pageType.Name, pageType.ID) fmt.Printf("Layout: %s\n", pageType.Layout) fmt.Printf("Properties: %d\n", len(pageType.Properties)) ``` -------------------------------- ### Get Objects in a View in Go Source: https://context7.com/epheo/anytype-go/llms.txt Fetch all objects contained within a specific view of a list. This requires the listID and the viewID. ```go viewsResp, _ := client.Space(spaceID).List(listID).Views().List(ctx) if len(viewsResp.Data) > 0 { viewID := viewsResp.Data[0].ID objectsResp, err := client.Space(spaceID).List(listID).View(viewID).Objects().List(ctx) if err != nil { panic(err) } fmt.Printf("View contains %d objects\n", len(objectsResp.Data)) for _, obj := range objectsResp.Data { fmt.Printf(" - %s\n", obj.Name) } } ``` -------------------------------- ### Get Object Type Key by Name Source: https://context7.com/epheo/anytype-go/llms.txt Look up the unique key of an object type given its display name. Handles cases where the type might not be found. ```go typeKey, err := client.Space(spaceID).Types().GetKeyByName(ctx, "Page") if err != nil { if err == anytype.ErrTypeNotFound { fmt.Println("Type not found") } panic(err) } fmt.Printf("Type key: %s\n", typeKey) ``` -------------------------------- ### Type Management API Source: https://context7.com/epheo/anytype-go/llms.txt APIs for managing object types within a space, including listing all types, retrieving a type by key, and getting a type's key by its name. ```APIDOC ## GET /api/types ### Description List all available object types in a space. ### Method GET ### Endpoint /api/types ### Response #### Success Response (200) - **Types** (array) - A list of available object types. - **Name** (string) - The display name of the type. - **Key** (string) - The unique key of the type. - **Layout** (string) - The layout associated with the type. - **Properties** (array) - The properties defined for the type. #### Response Example ```json [ { "Name": "Page", "Key": "page", "Layout": "page", "Properties": [...] } ] ``` ## GET /api/types/{typeKey} ### Description Retrieve a specific type by its key. ### Method GET ### Endpoint /api/types/{typeKey} ### Parameters #### Path Parameters - **typeKey** (string) - Required - The key of the type to retrieve. ### Response #### Success Response (200) - **Type** (object) - The details of the requested object type. - **ID** (string) - The unique identifier of the type. - **Name** (string) - The display name of the type. - **Key** (string) - The unique key of the type. - **Layout** (string) - The layout associated with the type. - **Properties** (array) - The properties defined for the type. #### Response Example ```json { "ID": "type-id-456", "Name": "Page", "Key": "page", "Layout": "page", "Properties": [ { "Name": "title", "Type": "text" } ] } ``` ## GET /api/types/key/{typeName} ### Description Look up a type's key by its display name. ### Method GET ### Endpoint /api/types/key/{typeName} ### Parameters #### Path Parameters - **typeName** (string) - Required - The display name of the type. ### Response #### Success Response (200) - **TypeKey** (string) - The key of the type. #### Response Example ```json { "TypeKey": "page" } ``` #### Error Response (404) - **Error** (string) - Indicates that the type was not found. #### Error Response Example ```json { "Error": "Type not found" } ``` ``` -------------------------------- ### Search with Complex Filters in Go Source: https://context7.com/epheo/anytype-go/llms.txt Perform searches using complex filter expressions with AND/OR operators and various condition types like text, checkbox, and number filters. This example also shows nested OR conditions. ```go results, err := client.Space(spaceID).Search(ctx, anytype.SearchRequest{ Query: "task", Filters: &anytype.FilterExpression{ Operator: anytype.FilterOperatorAnd, Conditions: []anytype.FilterItem{ anytype.TextFilter("name", anytype.FilterConditionContains, "important"), anytype.CheckboxFilter("completed", anytype.FilterConditionEq, false), anytype.NumberFilter("priority", anytype.FilterConditionGte, 1), }, }, }) if err != nil { panic(err) } // Using OR operator with nested conditions results, err = client.Space(spaceID).Search(ctx, anytype.SearchRequest{ Query: "", Filters: &anytype.FilterExpression{ Operator: anytype.FilterOperatorOr, Filters: []anytype.FilterExpression{ { Conditions: []anytype.FilterItem{ anytype.SelectFilter("status", anytype.FilterConditionEq, "in-progress-tag-id"), }, }, { Conditions: []anytype.FilterItem{ anytype.SelectFilter("status", anytype.FilterConditionEq, "blocked-tag-id"), }, }, }, }, }) if err != nil { panic(err) } fmt.Printf("Found %d matching objects\n", len(results.Data)) ``` -------------------------------- ### Prepare and Tag a Release Source: https://github.com/epheo/anytype-go/blob/main/CONTRIBUTING.md Use these git commands to tag and push a new release version. Ensure the version is updated in `version.go` before committing. ```bash git tag -a vX.Y.Z -m "Release vX.Y.Z" git push origin vX.Y.Z ``` -------------------------------- ### Import Anytype-Go SDK Packages Source: https://github.com/epheo/anytype-go/blob/main/README.md Import the main SDK package and the client package for use in your Go application. ```go import ( "github.com/epheo/anytype-go" _ "github.com/epheo/anytype-go/client" ) ``` -------------------------------- ### Create a Property with Tags Source: https://context7.com/epheo/anytype-go/llms.txt Use this to create a new property in a space. Predefined tags can be included for multi-select or select properties. ```go propResp, err := client.Space(spaceID).Properties().Create(ctx, anytype.CreatePropertyRequest{ Name: "Priority", Format: "multi_select", Key: "priority", // Optional Tags: []anytype.CreateTagRequest{ {Name: "Critical", Color: "red"}, {Name: "High", Color: "orange"}, {Name: "Medium", Color: "yellow"}, {Name: "Low", Color: "blue"}, }, }) if err != nil { panic(err) } fmt.Printf("Created property: %s (Key: %s, Format: %s) ", propResp.Property.Name, propResp.Property.Key, propResp.Property.Format) ``` -------------------------------- ### Create a New Space Source: https://context7.com/epheo/anytype-go/llms.txt Create a new space with a specified name and an optional description. ```go newSpace, err := client.Spaces().Create(ctx, anytype.CreateSpaceRequest{ Name: "My Project Space", Description: "A space for project documentation", }) if err != nil { panic(err) } fmt.Printf("Created space: %s (ID: %s)\n", newSpace.Space.Name, newSpace.Space.ID) ``` -------------------------------- ### List Templates for a Type Source: https://github.com/epheo/anytype-go/blob/main/README.md Fetch all available templates associated with a particular type within a space. ```go templates, _ := client.Space(spaceID).Type(typeKey).Templates().List(ctx) ``` -------------------------------- ### Run API Coverage Tests Source: https://github.com/epheo/anytype-go/blob/main/README.md Execute API coverage tests for the Anytype-Go SDK using the 'go test' command. ```bash go test -v ./tests_api_coverage/... ``` -------------------------------- ### Create a Collection (List) in Go Source: https://context7.com/epheo/anytype-go/llms.txt Create a new collection, which functions as a list or container for organizing objects within a space. Requires a spaceID. ```go collection, err := client.Space(spaceID).Objects().Create(ctx, anytype.CreateObjectRequest{ TypeKey: "collection", Name: "Q1 Tasks", Icon: &anytype.Icon{ Format: anytype.IconFormatEmoji, Emoji: "📋", }, }) if err != nil { panic(err) } listID := collection.Object.ID fmt.Printf("Created collection: %s (ID: %s)\n", collection.Object.Name, listID) ``` -------------------------------- ### Create a Tag Source: https://context7.com/epheo/anytype-go/llms.txt Add a new tag to a property that supports tags (e.g., select, multi-select). An optional key can be provided. ```go newTag, err := client.Space(spaceID).Property(propertyID).Tags().Create(ctx, anytype.CreateTagRequest{ Name: "Urgent", Color: "red", Key: "urgent", // Optional }) if err != nil { panic(err) } fmt.Printf("Created tag: %s (Color: %s) ", newTag.Tag.Name, newTag.Tag.Color) ``` -------------------------------- ### Authentication API Source: https://context7.com/epheo/anytype-go/llms.txt This section covers the authentication flow for the Anytype Go SDK, including creating a challenge, obtaining an API key, and establishing an authenticated client connection. ```APIDOC ## Authentication ### Create Challenge and API Key Authenticate with the Anytype local API using a challenge-response flow. The user must enter the verification code displayed in the Anytype app. ```go package main import ( "context" "fmt" "time" "github.com/epheo/anytype-go" _ "github.com/epheo/anytype-go/client" // Register client implementation ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Create unauthenticated client client := anytype.NewClient( anytype.WithBaseURL("http://localhost:31009"), ) // Step 1: Initiate challenge - Anytype app displays verification code authResponse, err := client.Auth().CreateChallenge(ctx, "MyApp") if err != nil { panic(err) } // Step 2: User enters the code shown in Anytype app fmt.Println("Enter the verification code from Anytype app:") var code string fmt.Scanln(&code) // Step 3: Exchange challenge for API key tokenResponse, err := client.Auth().CreateApiKey(ctx, authResponse.ChallengeID, code) if err != nil { panic(err) } // Step 4: Create authenticated client authenticatedClient := anytype.NewClient( anytype.WithBaseURL("http://localhost:31009"), anytype.WithAppKey(tokenResponse.ApiKey), ) fmt.Printf("Authenticated! API Key: %s...\n", tokenResponse.ApiKey[:10]) _ = authenticatedClient } ``` ``` -------------------------------- ### List Views for a List in Go Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve all configured views for a given list or collection. This includes view names, layouts, filters, and sorting configurations. ```go viewsResp, err := client.Space(spaceID).List(listID).Views().List(ctx) if err != nil { panic(err) } for _, view := range viewsResp.Data { fmt.Printf("View: %s (Layout: %s)\n", view.Name, view.Layout) for _, filter := range view.Filters { fmt.Printf(" Filter: %s %s %s\n", filter.PropertyKey, filter.Condition, filter.Value) } for _, sort := range view.Sorts { fmt.Printf(" Sort: %s %s\n", sort.PropertyKey, sort.SortType) } } ``` -------------------------------- ### List All Spaces Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve all spaces available to the authenticated user. The response includes pagination information. ```go spacesResp, err := client.Spaces().List(ctx) if err != nil { panic(err) } for _, space := range spacesResp.Data { fmt.Printf("Space: %s (ID: %s)\n", space.Name, space.ID) } // Response includes pagination info fmt.Printf("Total: %d, HasMore: %v\n", spacesResp.Pagination.Total, spacesResp.Pagination.HasMore) ``` -------------------------------- ### List Tags for a Property Source: https://github.com/epheo/anytype-go/blob/main/README.md Fetch all tags associated with a particular property within a space. ```go tags, _ := client.Space(spaceID).Property(propID).Tags().List(ctx) ``` -------------------------------- ### Create a New Anytype Object Source: https://context7.com/epheo/anytype-go/llms.txt Use this to create a new object with specified type, name, content, icon, and custom properties. Ensure the spaceID is valid and the object type exists. ```go newObject, err := client.Space(spaceID).Objects().Create(ctx, anytype.CreateObjectRequest{ TypeKey: "page", Name: "Meeting Notes - Q1 Review", Body: "# Meeting Notes\n\n## Agenda\n\n- Review Q1 performance\n- Discuss Q2 goals\n- Action items", Icon: &anytype.Icon{ Format: anytype.IconFormatEmoji, Emoji: "📝", }, TemplateID: "optional-template-id", // Use a template if available Properties: []anytype.PropertyLinkValue{ anytype.TextPropertyLinkValue{Key: "description", Text: "Quarterly review meeting"}, anytype.DatePropertyLinkValue{Key: "due_date", Date: ptrString("2025-03-15")}, anytype.CheckboxPropertyLinkValue{Key: "completed", Checkbox: false}, }, }) if err != nil { panic(err) } fmt.Printf("Created object: %s (ID: %s)\n", newObject.Object.Name, newObject.Object.ID) // Helper function for creating string pointers func ptrString(s string) *string { return &s } ``` -------------------------------- ### Global Search Source: https://github.com/epheo/anytype-go/blob/main/README.md Perform a search across all spaces for specific content. ```go globalResults, _ := client.Search().Search(ctx, anytype.SearchRequest{Query: "notes"}) ``` -------------------------------- ### Filter Constructors Reference in Go Source: https://context7.com/epheo/anytype-go/llms.txt Reference for using convenience constructors provided by the SDK for various filter types, including text, number, checkbox, select, multi-select, date, URL, email, phone, files, objects, and empty/not empty checks. Also lists available filter conditions. ```go // Text filters anytype.TextFilter("name", anytype.FilterConditionContains, "search term") anytype.TextFilter("description", anytype.FilterConditionEq, "exact match") // Number filters anytype.NumberFilter("price", anytype.FilterConditionGte, 100.0) anytype.NumberFilter("quantity", anytype.FilterConditionLt, 50) // Checkbox filters anytype.CheckboxFilter("completed", anytype.FilterConditionEq, true) // Select filters (for single-select properties) anytype.SelectFilter("status", anytype.FilterConditionEq, "tag-id") // Multi-select filters anytype.MultiSelectFilter("tags", anytype.FilterConditionAll, []string{"tag1", "tag2"}) anytype.MultiSelectFilter("categories", anytype.FilterConditionIn, []string{"cat1", "cat2"}) // Date filters anytype.DateFilter("due_date", anytype.FilterConditionLte, "2025-12-31") // URL, Email, Phone filters anytype.URLFilter("website", anytype.FilterConditionContains, "example.com") anytype.EmailFilter("contact", anytype.FilterConditionEq, "user@example.com") anytype.PhoneFilter("phone", anytype.FilterConditionContains, "+1") // Files and Objects filters anytype.FilesFilter("attachments", anytype.FilterConditionNEmpty, nil) anytype.ObjectsFilter("related", anytype.FilterConditionIn, []string{"obj1", "obj2"}) // Empty/Not empty checks anytype.EmptyFilter("optional_field", anytype.FilterConditionEmpty) anytype.EmptyFilter("required_field", anytype.FilterConditionNEmpty) // Filter conditions available: // eq, ne, in, nin, empty, nempty, contains, ncontains, gt, lt, gte, lte, all ``` -------------------------------- ### List Templates for a Type in Go Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve all available templates associated with a specific object type, such as 'page'. ```go templates, err := client.Space(spaceID).Type("page").Templates().List(ctx) if err != nil { panic(err) } for _, template := range templates { fmt.Printf("Template: %s (ID: %s)\n", template.Name, template.ID) } ``` -------------------------------- ### Basic Search in a Space Source: https://context7.com/epheo/anytype-go/llms.txt Perform a basic search for objects within a space using a query string. The results include the object's name and type. ```go results, err := client.Space(spaceID).Search(ctx, anytype.SearchRequest{ Query: "meeting notes", }) if err != nil { panic(err) } fmt.Printf("Found %d objects matching 'meeting notes' ", len(results.Data)) for _, obj := range results.Data { fmt.Printf(" - %s (Type: %s) ", obj.Name, obj.Type.Name) } ``` -------------------------------- ### Global Search Across All Spaces in Go Source: https://context7.com/epheo/anytype-go/llms.txt Perform a search query across all spaces the user has access to. Results can be sorted by properties like name. ```go globalResults, err := client.Search().Search(ctx, anytype.SearchRequest{ Query: "important document", Sort: &anytype.SortOptions{ Property: anytype.SortPropertyName, Direction: anytype.SortDirectionAsc, }, }) if err != nil { panic(err) } fmt.Printf("Found %d objects across all spaces\n", len(globalResults.Data)) for _, obj := range globalResults.Data { fmt.Printf(" - %s (Space: %s)\n", obj.Name, obj.SpaceID) } ``` -------------------------------- ### List Spaces Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve a list of all spaces available in the Anytype application. ```go // Spaces spaces, _ := client.Spaces().List(ctx) ``` -------------------------------- ### List Space Properties in Go Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve a list of all properties defined within a specific Anytype space. This includes property names, keys, and formats. ```go properties, err := client.Space(spaceID).Properties().List(ctx) if err != nil { panic(err) } for _, prop := range properties { fmt.Printf("Property: %s (Key: %s, Format: %s)\n", prop.Name, prop.Key, prop.Format) } ``` -------------------------------- ### List Properties in a Space Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve a list of all properties defined within a specific space. ```go // Properties and tags props, _ := client.Space(spaceID).Properties().List(ctx) ``` -------------------------------- ### Authenticate with Anytype Local API Source: https://context7.com/epheo/anytype-go/llms.txt Authenticate using a challenge-response flow. The user must enter a verification code displayed in the Anytype app. This process involves creating a challenge, obtaining user input, and exchanging the challenge for an API key to create an authenticated client. ```go package main import ( "context" "fmt" "time" "github.com/epheo/anytype-go" _ "github.com/epheo/anytype-go/client" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Create unauthenticated client client := anytype.NewClient( anytype.WithBaseURL("http://localhost:31009"), ) // Step 1: Initiate challenge - Anytype app displays verification code authResponse, err := client.Auth().CreateChallenge(ctx, "MyApp") if err != nil { panic(err) } // Step 2: User enters the code shown in Anytype app fmt.Println("Enter the verification code from Anytype app:") var code string fmt.Scanln(&code) // Step 3: Exchange challenge for API key tokenResponse, err := client.Auth().CreateApiKey(ctx, authResponse.ChallengeID, code) if err != nil { panic(err) } // Step 4: Create authenticated client authenticatedClient := anytype.NewClient( anytype.WithBaseURL("http://localhost:31009"), anytype.WithAppKey(tokenResponse.ApiKey), ) fmt.Printf("Authenticated! API Key: %s...\n", tokenResponse.ApiKey[:10]) _ = authenticatedClient } ``` -------------------------------- ### List All Object Types in a Space Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve a list of all available object types within a specified space. This is useful for understanding the schema available in your Anytype environment. ```go types, err := client.Space(spaceID).Types().List(ctx) if err != nil { panic(err) } for _, t := range types { fmt.Printf("Type: %s (Key: %s, Layout: %s)\n", t.Name, t.Key, t.Layout) } ``` -------------------------------- ### List Objects in a Space Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve a list of objects within a specified space. Supports custom pagination using WithLimit and WithOffset options. ```go // List with default pagination objects, err := client.Space(spaceID).Objects().List(ctx) if err != nil { panic(err) } fmt.Printf("Found %d objects\n", len(objects)) // List with pagination options objects, err = client.Space(spaceID).Objects().List(ctx, anytype.WithLimit(10), anytype.WithOffset(0), ) if err != nil { panic(err) } for _, obj := range objects { fmt.Printf("Object: %s (Type: %s, Layout: %s)\n", obj.Name, obj.Type.Name, obj.Layout) } ``` -------------------------------- ### List Objects in a Space Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve all objects within a specified space. ```go // Objects objects, _ := client.Space(spaceID).Objects().List(ctx) ``` -------------------------------- ### List Views for a List Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve all views associated with a specific list within a space. ```go // Lists and views views, _ := client.Space(spaceID).List(listID).Views().List(ctx) ``` -------------------------------- ### Create a Custom Type in Go Source: https://context7.com/epheo/anytype-go/llms.txt Use this to define a new object type with custom properties in your Anytype space. Ensure you have the spaceID and context initialized. ```go newType, err := client.Space(spaceID).Types().Create(ctx, anytype.CreateTypeRequest{ Name: "Product", Key: "product", // Optional, auto-generated if not provided Layout: "basic", PluralName: "Products", Icon: &anytype.Icon{ Format: anytype.IconFormatEmoji, Emoji: "📦", }, Properties: []anytype.PropertyDefinition{ {Key: "price", Name: "Price", Format: "number"}, {Key: "category", Name: "Category", Format: "select"}, {Key: "description", Name: "Description", Format: "text"}, {Key: "in_stock", Name: "In Stock", Format: "checkbox"}, }, }) if err != nil { panic(err) } fmt.Printf("Created type: %s (Key: %s)\n", newType.Type.Name, newType.Type.Key) for _, prop := range newType.Type.Properties { fmt.Printf(" Property: %s (%s)\n", prop.Name, prop.Format) } ``` -------------------------------- ### Update a Space Source: https://context7.com/epheo/anytype-go/llms.txt Modify the name and description of an existing space. Note that the request fields are pointers, allowing partial updates. ```go name := "Updated Space Name" description := "New description for the space" updatedSpace, err := client.Space("space-id-here").Update(ctx, anytype.UpdateSpaceRequest{ Name: &name, Description: &description, }) if err != nil { panic(err) } fmt.Printf("Updated space: %s\n", updatedSpace.Space.Name) ``` -------------------------------- ### Update a Tag Source: https://context7.com/epheo/anytype-go/llms.txt Modify the name, color, or key of an existing tag. Ensure you have the correct property and tag IDs. ```go updatedTag, err := client.Space(spaceID).Property(propertyID).Tag(tagID).Update(ctx, anytype.UpdateTagRequest{ Name: "Very Urgent", Color: "pink", }) if err != nil { panic(err) } fmt.Printf("Updated tag: %s ", updatedTag.Tag.Name) ``` -------------------------------- ### Retrieve Object Details Source: https://context7.com/epheo/anytype-go/llms.txt Fetch details of a specific object by its ID. You can retrieve full details or the object's content in markdown format using the `WithFormat("md")` option. ```go // Get object with full details objectDetails, err := client.Space(spaceID).Object(objectID).Get(ctx) if err != nil { panic(err) } fmt.Printf("Name: %s\n", objectDetails.Object.Name) fmt.Printf("Type: %s\n", objectDetails.Object.Type.Name) fmt.Printf("Layout: %s\n", objectDetails.Object.Layout) fmt.Printf("Archived: %v\n", objectDetails.Object.Archived) for _, prop := range objectDetails.Object.Properties { fmt.Printf("Property %s: %s\n", prop.Name, prop.Text) } // Get object as markdown export markdownResp, err := client.Space(spaceID).Object(objectID).Get(ctx, anytype.WithFormat("md")) if err != nil { panic(err) } fmt.Printf("Markdown content:\n%s\n", markdownResp.Object.Markdown) ``` -------------------------------- ### List Members in a Space Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve a list of all members belonging to a specific space. ```go // Members members, _ := client.Space(spaceID).Members().List(ctx) ``` -------------------------------- ### List Types in a Space Source: https://github.com/epheo/anytype-go/blob/main/README.md Retrieve a list of all defined types within a specific space. ```go // Types and templates types, _ := client.Space(spaceID).Types().List(ctx) ``` -------------------------------- ### List Space Members Source: https://context7.com/epheo/anytype-go/llms.txt Retrieve a list of all members belonging to a specific space. This includes their names, roles, and statuses. ```go membersResp, err := client.Space(spaceID).Members().List(ctx) if err != nil { panic(err) } for _, member := range membersResp.Data { fmt.Printf("Member: %s (Role: %s, Status: %s) ", member.Name, member.Role, member.Status) } // Member roles: viewer, editor, owner, no_permission // Member statuses: joining, active, removed, declined, removing, canceled ``` -------------------------------- ### Object Management API Source: https://context7.com/epheo/anytype-go/llms.txt APIs for managing objects within a space, including creation, retrieval, update, and deletion. ```APIDOC ## POST /api/objects ### Description Create a new object with type, name, body content, icon, and custom properties. ### Method POST ### Endpoint /api/objects ### Parameters #### Request Body - **TypeKey** (string) - Required - The key of the object type. - **Name** (string) - Required - The name of the object. - **Body** (string) - Optional - The markdown content of the object. - **Icon** (object) - Optional - The icon for the object. - **Format** (string) - Required - The format of the icon (e.g., "emoji"). - **Emoji** (string) - Required if Format is "emoji" - The emoji character. - **TemplateID** (string) - Optional - The ID of the template to use. - **Properties** (array) - Optional - Custom properties for the object. - **Key** (string) - Required - The key of the property. - **Text** (string) - Required for TextPropertyLinkValue - The text value. - **Date** (string) - Required for DatePropertyLinkValue - The date value in ISO format. - **Checkbox** (boolean) - Required for CheckboxPropertyLinkValue - The checkbox state. ### Request Example ```json { "TypeKey": "page", "Name": "Meeting Notes - Q1 Review", "Body": "# Meeting Notes\n\n## Agenda\n\n- Review Q1 performance\n- Discuss Q2 goals\n- Action items", "Icon": { "Format": "emoji", "Emoji": "📝" }, "TemplateID": "optional-template-id", "Properties": [ { "Key": "description", "Text": "Quarterly review meeting" }, { "Key": "due_date", "Date": "2025-03-15" }, { "Key": "completed", "Checkbox": false } ] } ``` ### Response #### Success Response (200) - **Object** (object) - The created object details. - **ID** (string) - The unique identifier of the object. - **Name** (string) - The name of the object. - **Type** (object) - The type of the object. - **Layout** (string) - The layout of the object. - **Archived** (boolean) - Whether the object is archived. - **Properties** (array) - The properties of the object. #### Response Example ```json { "Object": { "ID": "object-id-123", "Name": "Meeting Notes - Q1 Review", "Type": {"Name": "Page", "Key": "page"}, "Layout": "page", "Archived": false, "Properties": [ { "Name": "description", "Text": "Quarterly review meeting" } ] } } ``` ## GET /api/objects/{objectID} ### Description Retrieve a specific object by ID, optionally in markdown format. ### Method GET ### Endpoint /api/objects/{objectID} ### Parameters #### Path Parameters - **objectID** (string) - Required - The ID of the object to retrieve. #### Query Parameters - **format** (string) - Optional - The desired format for the object (e.g., "md" for markdown). ### Response #### Success Response (200) - **Object** (object) - The requested object details. - **ID** (string) - The unique identifier of the object. - **Name** (string) - The name of the object. - **Type** (object) - The type of the object. - **Layout** (string) - The layout of the object. - **Archived** (boolean) - Whether the object is archived. - **Properties** (array) - The properties of the object. - **Markdown** (string) - The markdown content of the object (if requested). #### Response Example ```json { "Object": { "ID": "object-id-123", "Name": "Meeting Notes - Q1 Review", "Type": {"Name": "Page", "Key": "page"}, "Layout": "page", "Archived": false, "Properties": [ { "Name": "description", "Text": "Quarterly review meeting" } ], "Markdown": "# Meeting Notes\n\n## Agenda\n\n- Review Q1 performance" } } ``` ## PUT /api/objects/{objectID} ### Description Update object properties including name, markdown content, icon, and custom properties. ### Method PUT ### Endpoint /api/objects/{objectID} ### Parameters #### Path Parameters - **objectID** (string) - Required - The ID of the object to update. #### Request Body - **Name** (string) - Optional - The updated name of the object. - **Markdown** (string) - Optional - The updated markdown content. - **Icon** (object) - Optional - The updated icon for the object. - **Format** (string) - Required - The format of the icon (e.g., "emoji"). - **Emoji** (string) - Required if Format is "emoji" - The emoji character. - **Properties** (array) - Optional - Updated custom properties for the object. - **Key** (string) - Required - The key of the property. - **Checkbox** (boolean) - Required for CheckboxPropertyLinkValue - The checkbox state. - **Number** (number) - Required for NumberPropertyLinkValue - The number value. - **MultiSelect** (array of strings) - Required for MultiSelectPropertyLinkValue - The selected options. - **URL** (string) - Required for URLPropertyLinkValue - The URL value. - **Email** (string) - Required for EmailPropertyLinkValue - The email address. ### Request Example ```json { "Name": "Updated Meeting Notes - Q1 Review", "Markdown": "# Updated Meeting Notes\n\n## Summary\n\nThe meeting was successful.", "Icon": { "Format": "emoji", "Emoji": "✅" }, "Properties": [ { "Key": "completed", "Checkbox": true }, { "Key": "priority", "Number": 1 }, { "Key": "tags", "MultiSelect": ["tag-id-1", "tag-id-2"] }, { "Key": "reference", "URL": "https://example.com" }, { "Key": "contact", "Email": "team@example.com" } ] } ``` ### Response #### Success Response (200) - **Object** (object) - The updated object details. - **ID** (string) - The unique identifier of the object. - **Name** (string) - The name of the object. #### Response Example ```json { "Object": { "ID": "object-id-123", "Name": "Updated Meeting Notes - Q1 Review" } } ``` ## DELETE /api/objects/{objectID} ### Description Delete an object by its ID. ### Method DELETE ### Endpoint /api/objects/{objectID} ### Parameters #### Path Parameters - **objectID** (string) - Required - The ID of the object to delete. ### Response #### Success Response (200) - **Object** (object) - The deleted object details. - **ID** (string) - The unique identifier of the object. - **Name** (string) - The name of the object. #### Response Example ```json { "Object": { "ID": "object-id-123", "Name": "Meeting Notes - Q1 Review" } } ``` ``` -------------------------------- ### Objects API Source: https://context7.com/epheo/anytype-go/llms.txt This section covers the API endpoints for managing objects within a space, including listing objects with optional pagination. ```APIDOC ## Objects ### List Objects in a Space List all objects within a space with optional pagination. ```go // List with default pagination objects, err := client.Space(spaceID).Objects().List(ctx) if err != nil { panic(err) } fmt.Printf("Found %d objects\n", len(objects)) // List with pagination options objects, err = client.Space(spaceID).Objects().List(ctx, anytype.WithLimit(10), anytype.WithOffset(0), ) if err != nil { panic(err) } for _, obj := range objects { fmt.Printf("Object: %s (Type: %s, Layout: %s)\n", obj.Name, obj.Type.Name, obj.Layout) } ``` ``` -------------------------------- ### Spaces API Source: https://context7.com/epheo/anytype-go/llms.txt This section details the API endpoints for managing spaces, including listing all spaces, creating new spaces, retrieving space details, and updating existing spaces. ```APIDOC ## Spaces ### List All Spaces Retrieve all spaces available to the authenticated user. ```go spacesResp, err := client.Spaces().List(ctx) if err != nil { panic(err) } for _, space := range spacesResp.Data { fmt.Printf("Space: %s (ID: %s)\n", space.Name, space.ID) } // Response includes pagination info fmt.Printf("Total: %d, HasMore: %v\n", spacesResp.Pagination.Total, spacesResp.Pagination.HasMore) ``` ### Create a Space Create a new space with a name and optional description. ```go newSpace, err := client.Spaces().Create(ctx, anytype.CreateSpaceRequest{ Name: "My Project Space", Description: "A space for project documentation", }) if err != nil { panic(err) } fmt.Printf("Created space: %s (ID: %s)\n", newSpace.Space.Name, newSpace.Space.ID) ``` ### Get Space Details Retrieve details for a specific space by its ID. ```go spaceDetails, err := client.Space("space-id-here").Get(ctx) if err != nil { panic(err) } fmt.Printf("Name: %s\n", spaceDetails.Space.Name) fmt.Printf("Description: %s\n", spaceDetails.Space.Description) fmt.Printf("Network ID: %s\n", spaceDetails.Space.NetworkID) ``` ### Update a Space Update space properties like name and description. ```go name := "Updated Space Name" description := "New description for the space" updatedSpace, err := client.Space("space-id-here").Update(ctx, anytype.UpdateSpaceRequest{ Name: &name, Description: &description, }) if err != nil { panic(err) } fmt.Printf("Updated space: %s\n", updatedSpace.Space.Name) ``` ```