Search code examples
google-slidesgoogle-slides-api

How to create sub bullet points (nested bullet points under bullet points) using Google Slides API


I'm trying to use the Google Slides API to create nested bullet points within a paragraph. Currently, I'm able to create a paragraph with bullet points, but I'm struggling to create sub-bullet points (nested bullet points) under existing bullet points.

Here's the current request body I'm using:

{
  "requests": [
    {
      "createParagraphBullets": {
        "objectId": "i0",
        "textRange": {
          "type": "ALL"
        },
        "bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
      }
    },
    {
      "createParagraphBullets": {
        "objectId": "i0",
        "textRange": {
          "type": "ALL"
        },
        "bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
      }
    }
  ]
}

How can I modify the above code to create sub bullet points (nested bullet points) under the bullet points created by the first request using the Google Slides API? I tried nestingLevel suggested by ChatGPT but no luck!

ChatGPT result:

{
    "requests": [
      {
        "createParagraphBullets": {
          "objectId": "i0",
          "textRange": {
            "type": "ALL"
          },
          "bulletPreset": "BULLET_DISC_CIRCLE_SQUARE"
        }
      },
      {
        "createParagraphBullets": {
          "objectId": "i0",
          "textRange": {
            "type": "ALL"
          },
          "bulletPreset": "BULLET_DISC_CIRCLE_SQUARE",
          "nestingLevel": 1
        }
      }
    ]
  }

sample image of what I want to achieve


Solution

  • I believe your goal is as follows.

    • You want to create a nest list in a text box on Google Slides.
    • You want to achieve this using "Method: presentations.batchUpdate" of Google Slides API.

    In this case, how about the following request body? Unfortunately, from your question, I couldn't understand your input situation. So, in this answer, the request body also includes creating a text box and the texts.

    Sample request body:

    To create the nest list, the tab \t is used in the inserting text. And also, at createParagraphBullets, "type": "ALL" is used. By this, the nest structure is automatically created using \t.

    {
      "requests": [
        {
          "createShape": {
            "shapeType": "RECTANGLE",
            "elementProperties": {
              "size": {
                "height": {
                  "unit": "PT",
                  "magnitude": 200
                },
                "width": {
                  "unit": "PT",
                  "magnitude": 200
                }
              },
              "pageObjectId": "###"  // <--- Please set your page object ID.
            },
            "objectId": "abc123456"
          }
        },
        {
          "insertText": {
            "text": "sample1\n\tsample2\n\t\tsample3",
            "objectId": "abc123456"
          }
        },
        {
          "createParagraphBullets": {
            "bulletPreset": "BULLET_DISC_CIRCLE_SQUARE",
            "objectId": "abc123456",
            "textRange": {
              "type": "ALL"
            }
          }
        }
      ]
    }
    

    The sample curl command using this request body is as follows.

    curl --request POST \
      'https://slides.googleapis.com/v1/presentations/{googleSlideId}:batchUpdate' \
      --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
      --header 'Accept: application/json' \
      --header 'Content-Type: application/json' \
      --data '{"requests":[{"createShape":{"shapeType":"RECTANGLE","elementProperties":{"size":{"height":{"unit":"PT","magnitude":200},"width":{"unit":"PT","magnitude":200}},"pageObjectId":"###"},"objectId":"abc123456"}},{"insertText":{"text":"sample1\n\tsample2\n\t\tsample3","objectId":"abc123456"}},{"createParagraphBullets":{"bulletPreset":"BULLET_DISC_CIRCLE_SQUARE","objectId":"abc123456","textRange":{"type":"ALL"}}}]}' \
      --compressed
    

    Testing:

    When the above request body is used, the following result is obtained.

    enter image description here

    References: