Skip to content

Bulk delete api #27

Open
Open

Description

@stackdump

Hello I recently used the go sdk to try to bulk delete my blog posts.

It looks like it may have taken down the site. (or I'm being rate limited/blocked)

if there is some form of rate limiting or other limitation - the SDK should perhaps support that.

Activity

  1. stackdump commented on Dec 16, 2025

    @stackdump
    Author

    here's what I tried

    package main
    
    import (
    	"bufio"
    	"fmt"
    	"os"
    	"strings"
    
    	"github.com/writeas/go-writeas/v2"
    )
    
    func main() {
    	reader := bufio.NewReader(os.Stdin)
    
    	fmt.Print("Write.as Username: ")
    	username, _ := reader.ReadString('\n')
    	username = strings.TrimSpace(username)
    
    	fmt.Print("Write.as Password: ")
    	password, _ := reader.ReadString('\n')
    	password = strings.TrimSpace(password)
    
    	c := writeas.NewClient()
    
    	fmt.Println("\nLogging in...")
    	u, err := c.LogIn(username, password)
    	if err != nil {
    		fmt.Printf("Login failed: %v\n", err)
    		os.Exit(1)
    	}
    	fmt.Printf("Logged in as %s\n", u.User.Username)
    
    	fmt.Println("\nFetching your posts...")
    	posts, err := c.GetUserPosts()
    	if err != nil {
    		fmt.Printf("Failed to fetch posts: %v\n", err)
    		os.Exit(1)
    	}
    
    	if len(*posts) == 0 {
    		fmt.Println("No posts found.")
    		os.Exit(0)
    	}
    
    	fmt.Printf("Found %d posts. Deleting...\n", len(*posts))
    	deleted := 0
    	failed := 0
    
    	for _, p := range *posts {
    		err := c.DeletePost(p.ID, p.Token)
    		if err != nil {
    			fmt.Printf("Failed to delete %s: %v\n", p.ID, err)
    			failed++
    		} else {
    			fmt.Printf("Deleted: %s\n", p.ID)
    			deleted++
    		}
    	}
    
    	fmt.Printf("\nDone! Deleted %d posts, %d failed.\n", deleted, failed)
    
    	fmt.Println("Logging out...")
    	c.LogOut()
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions