Search code examples
javascriptpython-3.xgoogle-docsgoogle-docs-apigoogle-developers-console

Google Docs API create an empty document


I try now to create a document with Ggoogle Docs APIwith my content, but every time i create it, it will be embty, what should i do to fix the problem?

I use the same code from google example to do this. link to example

My Content example:

      {
        "title": "testitesti",
        "body": {
          "content": [
            {
              "endIndex": 1,
              "sectionBreak": {
                "sectionStyle": {
                  "columnSeparatorStyle": "NONE",
                  "contentDirection": "LEFT_TO_RIGHT",
                  "sectionType": "CONTINUOUS"
                }
              }
            },
            {
              "startIndex": 1,
              "endIndex": 6,
              "paragraph": {
                "elements": [
                  {
                    "startIndex": 1,
                    "endIndex": 6,
                    "textRun": {
                      "content": "test\n",
                      "textStyle": {}
                    }
                  }
                ],
                "paragraphStyle": {
                  "namedStyleType": "NORMAL_TEXT",
                  "direction": "LEFT_TO_RIGHT"
                }
              }
            }
          ]
        }
      }

Thanks


Solution

  • documents.create will always create blank documents:

    Creates a blank document using the title given in the request. Other fields in the request, including any provided content, are ignored.

    If you want to add content to your document using document resource properties, use documents.batchUpdate.