# Method: documents.annotateText

- [HTTP request](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#body.HTTP_TEMPLATE)
- [Request body](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#body.request_body)
  - [JSON representation](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#body.request_body.SCHEMA_REPRESENTATION)
- [Response body](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#body.response_body)
  - [JSON representation](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#body.AnnotateTextResponse.SCHEMA_REPRESENTATION)
- [Authorization scopes](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#body.aspect)
- [Features](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features)
  - [JSON representation](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features.SCHEMA_REPRESENTATION)
- [Try it!](https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#try-it)

A convenience method that provides all features in one call.

### HTTP request

`POST https://language.googleapis.com/v2/documents:annotateText`

The URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.

### Request body

The request body contains data with the following structure:

| JSON representation |
|---|
| ``` { "document": { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents#Document`) }, "features": { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features`) }, "encodingType": enum (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/EncodingType`) } ``` |

| Fields ||
|---|---|
| `document` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents#Document`)`` Required. Input document. |
| `features` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features`)`` Required. The enabled features. |
| `encodingType` | ``enum (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/EncodingType`)`` The encoding type used by the API to calculate offsets. |

### Response body

The text annotations response message.

If successful, the response body contains data with the following structure:

| JSON representation |
|---|
| ``` { "sentences": [ { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/Sentence`) } ], "entities": [ { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/Entity`) } ], "documentSentiment": { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/Sentiment`) }, "languageCode": string, "categories": [ { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/ClassificationCategory`) } ], "moderationCategories": [ { object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/ClassificationCategory`) } ], "languageSupported": boolean } ``` |

| Fields ||
|---|---|
| `sentences[]` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/Sentence`)`` Sentences in the input document. Populated if the user enables `https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features.FIELDS.extract_document_sentiment`. |
| `entities[]` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/Entity`)`` Entities, along with their semantic information, in the input document. Populated if the user enables `https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features.FIELDS.extract_entities` or `AnnotateTextRequest.Features.extract_entity_sentiment`. |
| `documentSentiment` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/Sentiment`)`` The overall sentiment for the document. Populated if the user enables `https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/documents/annotateText#Features.FIELDS.extract_document_sentiment`. |
| `languageCode` | `string` The language of the text, which will be the same as the language specified in the request or, if not specified, the automatically-detected language. See \[Document.language\]\[\] field for more details. |
| `categories[]` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/ClassificationCategory`)`` Categories identified in the input document. |
| `moderationCategories[]` | ``object (`https://docs.cloud.google.com/natural-language/docs/reference/rest/v2/ClassificationCategory`)`` Harmful and sensitive categories identified in the input document. |
| `languageSupported` | `boolean` Whether the language is officially supported by all requested features. The API may still return a response when the language is not supported, but it is on a best effort basis. |

### Authorization scopes

Requires one of the following OAuth scopes:

- `https://www.googleapis.com/auth/cloud-language`
- `https://www.googleapis.com/auth/cloud-platform`

For more information, see the [Authentication Overview](https://cloud.google.com/docs/authentication/).

## Features

All available features. Setting each one to true will enable that specific analysis for the input.

| JSON representation |
|---|
| ``` { "extractEntities": boolean, "extractDocumentSentiment": boolean, "classifyText": boolean, "moderateText": boolean } ``` |

| Fields ||
|---|---|
| `extractEntities` | `boolean` Optional. Extract entities. |
| `extractDocumentSentiment` | `boolean` Optional. Extract document-level sentiment. |
| `classifyText` | `boolean` Optional. Classify the full document into categories. |
| `moderateText` | `boolean` Optional. Moderate the document for harmful and sensitive categories. |