google-docs-api

Why doesn’t @date appear in the JSON response from the Google Docs API?


I’m working with the Google Docs API to retrieve the contents of a document.

Used documents.get with the correct documentId and retrieved the document body. The JSON response does not include the @date in it.

Is there a way to get @date in the JSON response?

{
  "startIndex": 1,
  "endIndex": 3,
  "paragraph": {
    "elements": [
      {
        "startIndex": 1,
        "endIndex": 3,
        "textRun": {
          "content": "\n",
          "textStyle": {}
        }
      }
    ],
    "paragraphStyle": {
      "namedStyleType": "NORMAL_TEXT",
      "direction": "LEFT_TO_RIGHT"
    }
  }
}

This is the response that I am getting.

I see that I need to use export feature of google drive to get the doc in pdf or txt to get the date.


Solution

  • Using files.export to Retrieve Smart Chip Values in Google Docs

    I attempted to research the capability of the document.get API to retrieve values from smart chips (e.g., people, dates, calendar events, or building blocks) included in a Google Doc. Unfortunately, I discovered that the document.get API currently lacks functionality to access smart chip values. No documentation exists that describes retrieving smart chip data via this API.

    However, I found a workaround using the files.export API from Google Drive. Here’s what I have found:

    1. I used the API Explorer to test the files.export API. By filling up the document ID and setting the mimeType to application/pdf, Although it retrieves its content, it currently is not readable as it is in a binary format, additional tools or conversions might be needed to process the PDF and extract readable data.
    2. Since I have yet to find that this retrieves the smart chips. I have tried to change the mimeType to text/plain to get the raw data of the document which then confirms that files.export API is capable of extracting the content of a document including values from smart chips like dates and names, building blocks, calendar events. You can replicate this by following the first step and adjusting the MIME type accordingly. While the plain text output includes smart chip values, it does not preserve the formatting or contextual information from the document.

    Using the basic API explorer of the documentation, The document.get API does not provide a way to retrieve values from smart chips, such as @date or other types in JSON response. To access these values, you must use the files.export API with text/plain as the mimeType. While this method allows you to extract smart chip data, it has limitations in terms of formatting and structure. For more complex use cases, additional processing may be required to parse and integrate the data.

    References: