How to Format Headers and Create Bullet Points Using Google Docs API

I’m working on a Python automation script that generates Google Docs content using their API. I can successfully create headers but I’m struggling with adding bullet lists.

My Goal

I want to create a document with this structure:

Header One
• list item

Header Two  
• list item

What Works

Creating headers works fine with this approach:

operations = []
current_op = {}

for item in reversed(my_data["items"]):
    # Add header text
    current_op = {
        "insertText": {
            "location": {"index": 1}, 
            "text": f"{item['title']}\n"
        }
    }
    operations.append(current_op)
    
    # Style as header
    current_op = {
        "updateParagraphStyle": {
            "range": {"startIndex": 1, "endIndex": len(item['title'])},
            "paragraphStyle": {
                "namedStyleType": "HEADING_2"
            }
        }
    }
    operations.append(current_op)

response = service.documents().batchUpdate(documentId=doc_id, body={'requests': operations}).execute()

The Problem

When I try to add bullets, I get an error about “oneof field ‘request’ is already set”:

list_text = "sample text"

for item in reversed(my_data["items"]):
    # Insert bullet text and create bullets in same request
    current_op = {
        "insertText": {"location": {"index": len(item['title']) + 2}, "text": list_text},
        "createParagraphBullets": {
            "range": {"startIndex": len(item['title']) + 2, "endIndex": len(list_text) + 2},
            "bulletPreset": "BULLET_ARROW_DIAMOND_DISC"
        }
    }
    operations.append(current_op)

I think I’m misunderstanding how to structure the batch requests properly. Should text insertion and bullet formatting be separate operations? Any help would be great!

yeah, that error’s straightforward - you can’t use insertText and createParagraphBullets in the same operation. I hit this same issue when I started with the docs API. split them into separate operations, and watch your index calculations. if you don’t account for the text you just added, your bullet ranges will be wrong.

You’re mixing two different request types in one operation - that won’t work. Each batch request can only do one thing at a time. Split them up: first insert your text, then apply the bullet formatting in a separate operation. Google Docs API is strict about this - one operation per request object. I ran into the exact same issue building a doc generator last year.

You can’t combine insertText and createParagraphBullets in one request - the API only handles one operation at a time. I had this exact issue when I was automating reports at work. Here’s what worked: insert your text first, then apply bullet formatting to that range in a separate request. Just be mindful of your indexes as they shift every time you insert something; keeping track of total characters inserted can help maintain the right indexes.