puter.threads.create()


Creates a new thread, either as a root thread or as a child of an existing thread.

Syntax

puter.threads.create(options);

Parameters

options (object) (required)

An object containing the following properties:

  • content (any) (required): The content to store in the thread.
  • parent_uuid (string) (optional): The UUID of the parent thread. If not provided, a root thread is created.

Return value

An object containing information about the created thread:

{
  uuid: string,       // The UUID of the created thread
  content: any,       // The content stored in the thread
  parent_uuid: string // The UUID of the parent thread (if applicable)
}

Permissions Required

To create a child thread, the current actor needs the thread:UUID-OF-PARENT:post permission. Root threads can be created without special permissions.

Example

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        // Create a root thread
        puter.threads.create({ content: "This is a root thread" })
            .then(rootThread => {
                console.log("Root thread created:", rootThread);
                
                // Create a child thread
                return puter.threads.create({ 
                    content: "This is a child thread", 
                    parent_uuid: rootThread.uuid 
                });
            })
            .then(childThread => {
                console.log("Child thread created:", childThread);
            })
            .catch(error => {
                console.error("Error creating threads:", error);
            });
    </script>
</body>
</html>