> [!CAUTION]
> **Caution** : Document AI Warehouse is deprecated and will no longer be available on Google Cloud after January 16, 2025. To safeguard your data, migrate any documents currently saved in Document AI Warehouse to an alternative like Cloud Storage. Verify that your data migration is completed before the discontinuation date to prevent any data loss. See [Deprecations](https://docs.cloud.google.com/document-warehouse/docs/deprecations) for details.

<br />

This document describes how to manage the document schemas in
Document AI Warehouse, including create, fetch, list, update, and delete operations.

## What are document schemas

Each document is of a certain document type and is specified by a schema.

A document schema defines the structure for a document type (for example,
Invoice or Paystub) in Document AI Warehouse, where admins can specify Properties of
different data types (Text \| Numeric \| Date \| Enumeration).

Properties are used to represent the extracted data, classification tags or
other business tags appended to documents by AI or human users - for example,
`Invoice_Amount` (numeric), `Due_Date` (date), or `Supplier_Name` (text).

1. **Property Attributes:** Each property can be declared as

   1. Filterable - can be used to filter search results

   2. Searchable - indexed so it can be found in search queries

   3. Required - `required` is used to ensure the property exists in
      the document
      (We recommend saving most properties as `required = false`, unless
      the property is required.)

2. **Extensible Schema:** in some cases, end users with Edit access need to
   add / delete new schema properties to documents. This is supported by a
   "MAP property", which is a list of key-value pairs.

   1. Each key-value pair in a MAP property can be a data-type of (Text \|
      Numeric \| Date \| Enumeration).

   2. For example, Invoice may contain a Map Property
      "Invoice_Entities" with the following key value pairs:

      - Invoice_Amount (numeric) 1000

      - Due_Date (date) 12/24/2021

      - Supplier_Name (text) ABC Corp

   3. **Immutability of Schema:** Note that Schema or Schema Properties
      can be added but currently cannot be edited or deleted, so define
      schema carefully.

## Before you begin

Before you begin, make sure you have completed the
[Quickstart](https://docs.cloud.google.com/document-warehouse/docs/quickstart) page.

## Create a schema

Create a document schema.

### REST

      curl --location --request POST --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas \
      --header "Content-Type: application/json" \
      --header "Authorization: Bearer $(gcloud auth print-access-token)" \
      --data '{
        "display_name": "Test Doc Schema",
        "property_definitions": [
          {
            "name": "plaintiff",
            "display_name": "Plaintiff",
            "is_searchable": true,
            "is_repeatable": true,
            "text_type_options": {}
          }
        ]
      }'

### Python


For more information, see the
[Document AI Warehouse Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    from google.cloud import contentwarehouse

    # TODO(developer): Uncomment these variables before running the sample.
    # project_number = 'YOUR_PROJECT_NUMBER'
    # location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'


    def sample_create_document_schema(project_number: str, location: str) -> None:
        """Creates document schema.

        Args:
            project_number: Google Cloud project number.
            location: Google Cloud project location.
        Returns:
            Response object.
        """
        # Create a Schema Service client.
        document_schema_client = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html()

        property_definition = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.PropertyDefinition.html(
            name="stock_symbol",  # Must be unique within a document schema (case insensitive)
            display_name="Searchable text",
            is_searchable=True,
            text_type_options=contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.TextTypeOptions.html(),
        )
        # Initialize request argument(s)
        document_schema = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.DocumentSchema.html(
            display_name="My Test Schema",
            property_definitions=[property_definition],
        )

        request = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.CreateDocumentSchemaRequest.html(
            # The full resource name of the location, e.g.:
            # projects/{project_number}/locations/{location}/
            parent=document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_common_location_path(project_number, location),
            document_schema=document_schema,
        )

        # Make the request
        response = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_create_document_schema(request=request)

        # Print response
        print("Document Schema Created:", response)

        return response

### Java


For more information, see the
[Document AI Warehouse Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/overview).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.CreateDocumentSchemaRequest.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.LocationName.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.TextTypeOptions.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeoutException;

    public class CreateDocumentSchema {

      public static void createDocumentSchema() throws IOException, 
            InterruptedException, ExecutionException, TimeoutException {
        String projectId = "your-project-id";
        String location = "your-region"; // Format is "us" or "eu".
        createDocumentSchema(projectId, location);
      }

      // Creates a new Document Schema
      public static void createDocumentSchema(String projectId, String location) throws IOException, 
            InterruptedException, ExecutionException, TimeoutException {
        String projectNumber = getProjectNumber(projectId);

        String endpoint = "contentwarehouse.googleapis.com:443";
        if (!"us".equals(location)) {
          endpoint = String.format("%s-%s", location, endpoint);
        }
        https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html documentSchemaServiceSettings = 
             https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html.newBuilder().setEndpoint(endpoint).build(); 

        // Create a Schema Service client
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html documentSchemaServiceClient =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html.create(documentSchemaServiceSettings)) {
          /*  The full resource name of the location, e.g.:
          projects/{project_number}/locations/{location} */
          String parent = https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.LocationName.html.format(projectNumber, location);

          /* Create Document Schema with Text Type Property Definition
           * More detail on managing Document Schemas: 
           * https://cloud.google.com/document-warehouse/docs/manage-document-schemas */
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html documentSchema = https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html.newBuilder()
              .setDisplayName("Test Doc Schema")
              .setDescription("Test Doc Schema's Description")
              .addPropertyDefinitions(
                https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.html.newBuilder()
                  .setName("plaintiff")
                  .setDisplayName("Plaintiff")
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setIsSearchable_boolean_(true)
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setIsRepeatable_boolean_(true)
                  .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setTextTypeOptions_com_google_cloud_contentwarehouse_v1_TextTypeOptions_(https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.TextTypeOptions.html.newBuilder().build())
                  .build()).build();

          // Define Document Schema request
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.CreateDocumentSchemaRequest.html createDocumentSchemaRequest =
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.CreateDocumentSchemaRequest.html.newBuilder()
                .setParent(parent)
                .setDocumentSchema(documentSchema).build();

          // Create Document Schema
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html documentSchemaResponse =
              documentSchemaServiceClient.createDocumentSchema(createDocumentSchemaRequest); 

          System.out.println(documentSchemaResponse.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html#com_google_cloud_contentwarehouse_v1_DocumentSchema_getName__());
        }
      }

      private static String getProjectNumber(String projectId) throws IOException { 
        /* Initialize client that will be used to send requests. 
        * This client only needs to be created once, and can be reused for multiple requests. */
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html projectsClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html.create()) { 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html projectName = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html.of(projectId); 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html project = projectsClient.getProject(projectName);
          String projectNumber = project.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html#com_google_cloud_resourcemanager_v3_Project_getName__(); // Format returned is projects/xxxxxx
          return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);
        } 
      }
    }

### Node.js


For more information, see the
[Document AI Warehouse Node.js API
reference documentation](https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    /**
     * TODO(developer): Uncomment these variables before running the sample.
     * const projectNumber = 'YOUR_PROJECT_NUMBER';
     * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
     */

    // Import from google cloud
    const {DocumentSchemaServiceClient} =
      require('https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest/overview.html').v1;

    const apiEndpoint =
      location === 'us'
        ? 'contentwarehouse.googleapis.com'
        : `${location}-contentwarehouse.googleapis.com`;

    // Create service client
    const serviceClient = new https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest/overview.html({
      apiEndpoint: apiEndpoint,
    });

    // Create Document Schema
    async function createDocumentSchema() {
      // The full resource name of the location, e.g.:
      // projects/{project_number}/locations/{location}
      const parent = `projects/${projectNumber}/locations/${location}`;
      // Initialize request argument(s)
      const request = {
        parent: parent,
        // Document Schema
        documentSchema: {
          displayName: 'My Test Schema',
          // Property Definition
          propertyDefinitions: [
            {
              name: 'testPropertyDefinitionName', // Must be unique within a document schema (case insensitive)
              displayName: 'searchable text',
              isSearchable: true,
              textTypeOptions: {},
            },
          ],
        },
      };

      // Make Request
      const response = serviceClient.createDocumentSchema(request);

      // Print out response
      response.then(
        result =>
          console.log(`Document Schema Created: ${JSON.stringify(result)}`),
        error => console.log(`${error}`)
      );
    }

<br />

## Get a schema

Get details of a document schema.

### REST

      curl --request GET --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/{document_schema_id} \
      --header "Authorization: Bearer $(gcloud auth print-access-token)" \
      --header "Content-Type: application/json; charset=UTF-8"

### Python


For more information, see the
[Document AI Warehouse Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    from google.cloud import contentwarehouse

    # TODO(developer): Uncomment these variables before running the sample.
    # project_number = 'YOUR_PROJECT_NUMBER'
    # location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'
    # document_schema_id = "YOUR_DOCUMENT SCHEMA_ID"


    def sample_get_document_schema(
        project_number: str, location: str, document_schema_id: str
    ) -> None:
        """Gets document schema details.

        Args:
            project_number: Google Cloud project number.
            location: Google Cloud project location.
            document_schema_id: Unique identifier for document schema
        Returns:
            Response object.
        """
        # Create a Schema Service client.
        document_schema_client = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html()

        # The full resource name of the location, e.g.:
        # projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id}
        document_schema_path = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_document_schema_path(
            project=project_number,
            location=location,
            document_schema=document_schema_id,
        )

        # Initialize request argument(s)
        request = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.GetDocumentSchemaRequest.html(
            name=document_schema_path,
        )

        # Make the request
        response = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_get_document_schema(request=request)

        # Handle the response
        print("Document Schema:", response)

        return response

### Java


For more information, see the
[Document AI Warehouse Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/overview).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.GetDocumentSchemaRequest.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeoutException;

    public class GetDocumentSchema {

      public static void getDocumentSchema() throws IOException, 
            InterruptedException, ExecutionException, TimeoutException {
        String projectId = "your-project-id";
        String location = "your-region"; // Format is "us" or "eu".
        String documentSchemaId = "your-document-schema-id";
        getDocumentSchema(projectId, location, documentSchemaId);
      }

      // Retrieves details about existing Document Schema
      public static void getDocumentSchema(String projectId, String location, 
            String documentSchemaId) throws IOException, 
                InterruptedException, ExecutionException, TimeoutException {
        String projectNumber = getProjectNumber(projectId);

        String endpoint = "contentwarehouse.googleapis.com:443";
        if (!"us".equals(location)) {
          endpoint = String.format("%s-%s", location, endpoint);
        }
        https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html documentSchemaServiceSettings = 
             https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html.newBuilder().setEndpoint(endpoint).build(); 

        // Create a Schema Service client
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html documentSchemaServiceClient =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html.create(documentSchemaServiceSettings)) {
          /* The full resource name of the location, e.g.: 
           projects/{project_number}/location/{location}/documentSchemas/{document_schema_id} */
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html documentSchemaName = 
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html.of(projectNumber, location, documentSchemaId);

          // Define request to get details of a specific Document Schema
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.GetDocumentSchemaRequest.html getDocumentSchemaRequest = 
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.GetDocumentSchemaRequest.html.newBuilder().setName(documentSchemaName.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html#com_google_cloud_contentwarehouse_v1_DocumentSchemaName_toString__()).build();

          // Get details of Document Schema
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html documentSchema = 
              documentSchemaServiceClient.getDocumentSchema(getDocumentSchemaRequest);

          System.out.println(documentSchema.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html#com_google_cloud_contentwarehouse_v1_DocumentSchema_getName__());
        }
      }

      private static String getProjectNumber(String projectId) throws IOException { 
        /* Initialize client that will be used to send requests. 
        * This client only needs to be created once, and can be reused for multiple requests. */
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html projectsClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html.create()) { 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html projectName = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html.of(projectId); 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html project = projectsClient.getProject(projectName);
          String projectNumber = project.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html#com_google_cloud_resourcemanager_v3_Project_getName__(); // Format returned is projects/xxxxxx
          return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);
        } 
      }
    }

### Node.js


For more information, see the
[Document AI Warehouse Node.js API
reference documentation](https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    /**
     * TODO(developer): Uncomment these variables before running the sample.
     * const projectNumber = 'YOUR_PROJECT_NUMBER';
     * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
     * const schemaId = 'YOUR_DOCUMENT_SCHEMA_ID';
     */

    // Import from google cloud
    const {DocumentSchemaServiceClient} =
      require('https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest/overview.html').v1;

    const apiEndpoint =
      location === 'us'
        ? 'contentwarehouse.googleapis.com'
        : `${location}-contentwarehouse.googleapis.com`;

    // Create service client
    const serviceClient = new https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest/overview.html({
      apiEndpoint: apiEndpoint,
    });

    // Get Document Schema
    async function getDocumentSchema() {
      // Initialize request argument(s)
      const request = {};

      // The full resource name of the location, e.g.:
      // projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id}
      const name = serviceClient.documentSchemaPath(
        projectNumber,
        location,
        documentSchemaId
      );
      request.name = name;

      // Make Request
      const response = serviceClient.getDocumentSchema(request);

      // Print out response
      response.then(
        result => console.log(`Schema Found: ${JSON.stringify(result)}`),
        error => console.log(`${error}`)
      );
    }

<br />

## List schemas

List document schemas.

### REST

      curl --request GET --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas \
      --header "Authorization: Bearer $(gcloud auth print-access-token)" \
      --header "Content-Type: application/json; charset=UTF-8"

### Python


For more information, see the
[Document AI Warehouse Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    from google.cloud import contentwarehouse

    # TODO(developer): Uncomment these variables before running the sample.
    # project_number = 'YOUR_PROJECT_NUMBER'
    # location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'


    def sample_list_document_schemas(project_number: str, location: str) -> None:
        """Lists document schemas.

        Args:
            project_number: Google Cloud project number.
            location: Google Cloud project location.
        """
        # Create a client
        document_schema_client = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html()

        # The full resource name of the location, e.g.:
        # projects/{project_number}/locations/{location}
        parent = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_common_location_path(
            project=project_number, location=location
        )

        # Initialize request argument(s)
        request = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.ListDocumentSchemasRequest.html(
            parent=parent,
        )

        # Make the request
        page_result = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_list_document_schemas(request=request)

        # Print response
        responses = []
        print("Document Schemas:")
        for response in page_result:
            print(response)
            responses.append(response)

        return responses

### Java


For more information, see the
[Document AI Warehouse Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/overview).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.ListDocumentSchemasRequest.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.LocationName.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeoutException;

    public class ListDocumentSchema {
      public static void listDocumentSchemas() throws IOException, 
            InterruptedException, ExecutionException, TimeoutException {
        String projectId = "your-project-id";
        String location = "your-region"; // Format is "us" or "eu".
        listDocumentSchemas(projectId, location);
      }

      // Retrieves all Document Schemas associated with a specified project
      public static void listDocumentSchemas(String projectId, String location) throws IOException, 
            InterruptedException, ExecutionException, TimeoutException {
        String projectNumber = getProjectNumber(projectId);

        String endpoint = "contentwarehouse.googleapis.com:443";
        if (!"us".equals(location)) {
          endpoint = String.format("%s-%s", location, endpoint);
        }
        https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html documentSchemaServiceSettings = 
             https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html.newBuilder().setEndpoint(endpoint).build(); 

        // Create a Schema Service client
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html documentSchemaServiceClient =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html.create(documentSchemaServiceSettings)) {
          /*  The full resource name of the location, e.g.:
          projects/{project_number}/locations/{location} */
          String parent = https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.LocationName.html.format(projectNumber, location);

          // Define request to list all Document Schemas
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.ListDocumentSchemasRequest.html listDocumentSchemasRequest = 
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.ListDocumentSchemasRequest.html.newBuilder().setParent(parent).build();

          // Print each schema ID  
          for (https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html schema :
              documentSchemaServiceClient.listDocumentSchemas(listDocumentSchemasRequest)
                .iterateAll()) {
            System.out.println(schema.getName());
          }
        }
      }

      private static String getProjectNumber(String projectId) throws IOException { 
        /* Initialize client that will be used to send requests. 
        * This client only needs to be created once, and can be reused for multiple requests. */
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html projectsClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html.create()) { 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html projectName = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html.of(projectId); 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html project = projectsClient.getProject(projectName);
          String projectNumber = project.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html#com_google_cloud_resourcemanager_v3_Project_getName__(); // Format returned is projects/xxxxxx
          return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);
        } 
      }
    }

<br />

## Delete a schema

Delete a document schema.

> [!NOTE]
> **Note:** You can't undo a delete operation. Also, the delete operation fails if there are documents under the schema.

### REST

      curl --request DELETE --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/{document_schema_id} \
      --header "Authorization: Bearer $(gcloud auth print-access-token)" \
      --header "Content-Type: application/json; charset=UTF-8"

### Python


For more information, see the
[Document AI Warehouse Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    from google.cloud import contentwarehouse

    # TODO(developer): Uncomment these variables before running the sample.
    # project_number = 'YOUR_PROJECT_NUMBER'
    # location = 'YOUR_PROJECT_LOCATION' # Format is 'us' or 'eu'
    # document_schema_id = "YOUR_DOCUMENT SCHEMA_ID"


    def sample_delete_document_schema(
        project_number: str, location: str, document_schema_id: str
    ) -> None:
        """Deletes document schema.

        Args:
            project_number: Google Cloud project number.
            location: Google Cloud project location.
            document_schema_id: Unique identifier for document schema
        Returns:
            None, if operation is successful
        """
        # Create a client
        document_schema_client = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html()

        # The full resource name of the location, e.g.:
        # projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id}
        document_schema_path = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_document_schema_path(
            project=project_number,
            location=location,
            document_schema=document_schema_id,
        )

        # Initialize request argument(s)
        request = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.DeleteDocumentSchemaRequest.html(
            name=document_schema_path,
        )

        # Make the request
        response = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_delete_document_schema(request=request)

        return response

### Java


For more information, see the
[Document AI Warehouse Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/overview).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DeleteDocumentSchemaRequest.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeoutException;

    public class DeleteDocumentSchema {

      public static void createDocumentSchema() throws IOException, 
            InterruptedException, ExecutionException, TimeoutException {
        String projectId = "your-project-id";
        String location = "your-region"; // Format is "us" or "eu".
        String documentSchemaId = "your-schema-id";
        deleteDocumentSchema(projectId, location, documentSchemaId);
      }

      // Creates a new Document Schema
      public static void deleteDocumentSchema(String projectId, String location,
          String documentSchemaId) throws IOException,
              InterruptedException, ExecutionException, TimeoutException {
        String projectNumber = getProjectNumber(projectId);

        String endpoint = "contentwarehouse.googleapis.com:443";
        if (!"us".equals(location)) {
          endpoint = String.format("%s-%s", location, endpoint);
        }
        https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html documentSchemaServiceSettings = 
             https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html.newBuilder().setEndpoint(endpoint).build(); 

        // Create a Schema Service client
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html documentSchemaServiceClient =
            https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html.create(documentSchemaServiceSettings)) {

          /* The full resource name of the location, e.g.: 
           projects/{project_number}/location/{location}/documentSchemas/{document_schema_id} */
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html documentSchemaName = 
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html.of(projectNumber, location, documentSchemaId);

          /* Create request to delete Document Schema from provided schema ID.
           * More detail on managing Document Schemas: 
           * https://cloud.google.com/document-warehouse/docs/manage-document-schemas */
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DeleteDocumentSchemaRequest.html deleteDocumentSchemaRequest = 
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DeleteDocumentSchemaRequest.html.newBuilder()
                .setName(documentSchemaName.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html#com_google_cloud_contentwarehouse_v1_DocumentSchemaName_toString__()).build();

          // Delete Document Schema
          documentSchemaServiceClient.deleteDocumentSchema(deleteDocumentSchemaRequest);

          System.out.println("Document Schema ID " + documentSchemaId + " has been deleted.");

        }
      }

      private static String getProjectNumber(String projectId) throws IOException { 
        /* Initialize client that will be used to send requests. 
        * This client only needs to be created once, and can be reused for multiple requests. */
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html projectsClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html.create()) { 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html projectName = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html.of(projectId); 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html project = projectsClient.getProject(projectName);
          String projectNumber = project.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html#com_google_cloud_resourcemanager_v3_Project_getName__(); // Format returned is projects/xxxxxx
          return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);
        } 
      }
    }

### Node.js


For more information, see the
[Document AI Warehouse Node.js API
reference documentation](https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    /**
     * TODO(developer): Uncomment these variables before running the sample.
     * const projectId = 'YOUR_PROJECT_ID';
     * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
     * const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID';
     */

    // Import from google cloud

    const {DocumentSchemaServiceClient} =
      require('https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest/overview.html').v1;

    const apiEndpoint =
      location === 'us'
        ? 'contentwarehouse.googleapis.com'
        : `${location}-contentwarehouse.googleapis.com`;

    // Create service client
    const serviceClient = new https://docs.cloud.google.com/nodejs/docs/reference/contentwarehouse/latest/overview.html({
      apiEndpoint: apiEndpoint,
    });

    // Delete Document Schema
    async function deleteDocumentSchema() {
      // Initialize request argument(s)
      const request = {
        // The full resource name of the location, e.g.:
        // projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id}
        name: `projects/${projectId}/locations/${location}/documentSchemas/${documentSchemaId}`,
      };

      // Make Request
      const response = await serviceClient.deleteDocumentSchema(request);

      // Print out response
      console.log(`Document Schema Deleted: ${JSON.stringify(response)}`);
    }

<br />

## Update a schema

Update a document schema. Currently the update logic only supports adding new
property definitions. The new document schema should include all property
definitions present in the existing schema.

- Supported:

  - For existing properties, users can change the following metadata settings: `is_repeatable`, `is_metadata`, `is_required`.
  - For existing ENUM properties, users can add new ENUM possible values or delete existing ENUM possible values. They can update the `EnumTypeOptions.validation_check_disabled` flag to disable the validation check. The validation check is used to make sure the ENUM values specified in the documents are in the range of possible ENUM values defined in the property definition when calling the `CreateDocument` API.
  - Adding new property definitions is supported.
- Not supported:

  - For existing schema, updates to `display_name` and `document_is_folder` are not allowed.
  - For existing properties, updates to `name`, `display_name` and `value_type_options` are not allowed.

> [!NOTE]
> **Note:** Allowed changes will take effect only for new documents and are not backward compatible.

### REST

    curl --request PATCH --url https://contentwarehouse.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION/documentSchemas/{document_schema_id} \
    --header "Authorization: Bearer $(gcloud auth print-access-token)" \
    --header "Content-Type: application/json; charset=UTF-8" \
    --data '{
      "document_schema": {
        "display_name": "Test Doc Schema",
        "property_definitions": [
          {
            "name": "plaintiff",
            "display_name": "Plaintiff",
            "is_repeatable": true,
            "text_type_options": {}
          }
        ]
      }
    }'

### Python


For more information, see the
[Document AI Warehouse Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    from google.cloud import contentwarehouse

    # TODO(developer): Uncomment these variables before running the sample.
    # project_number = "YOUR_PROJECT_NUMBER"
    # location = "us" # Format is 'us' or 'eu'
    # document_schema_id = "YOUR_SCHEMA_ID"


    def update_document_schema(
        project_number: str, location: str, document_schema_id: str
    ) -> None:
        # Create a Schema Service client
        document_schema_client = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html()

        # The full resource name of the location, e.g.:
        # projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id}
        document_schema_path = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_document_schema_path(
            project=project_number,
            location=location,
            document_schema=document_schema_id,
        )

        # Define Schema Property of Text Type with updated values
        updated_property_definition = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.PropertyDefinition.html(
            name="stock_symbol",  # Must be unique within a document schema (case insensitive)
            display_name="Searchable text",
            is_searchable=True,
            is_repeatable=False,
            is_required=True,
            text_type_options=contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.TextTypeOptions.html(),
        )

        # Define Update Document Schema Request
        update_document_schema_request = contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.UpdateDocumentSchemaRequest.html(
            name=document_schema_path,
            document_schema=contentwarehouse.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.types.DocumentSchema.html(
                display_name="My Test Schema",
                property_definitions=[updated_property_definition],
            ),
        )

        # Update Document schema
        updated_document_schema = document_schema_client.https://docs.cloud.google.com/python/docs/reference/contentwarehouse/latest/google.cloud.contentwarehouse_v1.services.document_schema_service.DocumentSchemaServiceClient.html#google_cloud_contentwarehouse_v1_services_document_schema_service_DocumentSchemaServiceClient_update_document_schema(
            request=update_document_schema_request
        )

        # Read the output
        print(f"Updated Document Schema: {updated_document_schema}")

### Java


For more information, see the
[Document AI Warehouse Java API
reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/overview).


To authenticate to Document AI Warehouse, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.TextTypeOptions.html;
    import com.google.cloud.contentwarehouse.v1.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.UpdateDocumentSchemaRequest.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html;
    import com.google.cloud.resourcemanager.v3.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html;
    import java.io.IOException;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeoutException;

    public class UpdateDocumentSchema {
      public static void updateDocumentSchema() throws IOException, 
            InterruptedException, ExecutionException, TimeoutException { 
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "your-project-id";
        String location = "your-region"; // Format is "us" or "eu".
        String documentSchemaId = "your-document-schema-id";
        /* The below method call retrieves details about the schema you are about to update.
         * It is important to note that some properties cannot be edited or removed. 
         * For more information on managing document schemas, please see the below documentation.
         * https://cloud.google.com/document-warehouse/docs/manage-document-schemas */
        GetDocumentSchema.getDocumentSchema(projectId, location, documentSchemaId);
        updateDocumentSchema(projectId, location, documentSchemaId);
      }

      // Updates an existing Document Schema
      public static void updateDocumentSchema(String projectId, String location, 
            String documentSchemaId) throws IOException, InterruptedException,
              ExecutionException, TimeoutException { 
        String projectNumber = getProjectNumber(projectId);

        String endpoint = "contentwarehouse.googleapis.com:443";
        if (!"us".equals(location)) {
          endpoint = String.format("%s-%s", location, endpoint);
        }

        https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html documentSchemaServiceSettings = 
                 https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceSettings.html.newBuilder().setEndpoint(endpoint).build(); 

        /* Create the Schema Service Client 
         * Initialize client that will be used to send requests. 
         * This client only needs to be created once, and can be reused for multiple requests. */
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html documentSchemaServiceClient = 
                https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaServiceClient.html.create(documentSchemaServiceSettings)) {

          /* The full resource name of the location, e.g.: 
           projects/{project_number}/location/{location}/documentSchemas/{document_schema_id} */
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html documentSchemaName = 
              https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html.of(projectNumber, location, documentSchemaId);

          // Define the new Schema Property with updated values
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.html propertyDefinition = https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.html.newBuilder()
              .setName("plaintiff")
              .setDisplayName("Plaintiff")
              .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setIsSearchable_boolean_(true)
              .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setIsRepeatable_boolean_(true)
              .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setIsRequired_boolean_(false)
              .https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.PropertyDefinition.Builder.html#com_google_cloud_contentwarehouse_v1_PropertyDefinition_Builder_setTextTypeOptions_com_google_cloud_contentwarehouse_v1_TextTypeOptions_(https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.TextTypeOptions.html.newBuilder()
              .build())
              .build();

          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html updatedDocumentSchema = https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html.newBuilder()
                        .setDisplayName("Test Doc Schema") 
                        .addPropertyDefinitions(0, propertyDefinition).build();

          // Create the Request to Update the Document Schema
          https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.UpdateDocumentSchemaRequest.html updateDocumentSchemaRequest = 
                https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.UpdateDocumentSchemaRequest.html.newBuilder()
                .setName(documentSchemaName.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchemaName.html#com_google_cloud_contentwarehouse_v1_DocumentSchemaName_toString__())
                .setDocumentSchema(updatedDocumentSchema)
                .build();

          // Update Document Schema
          updatedDocumentSchema = 
            documentSchemaServiceClient.updateDocumentSchema(updateDocumentSchemaRequest);

          // Read the output of Updated Document Schema Name
          System.out.println(updatedDocumentSchema.https://docs.cloud.google.com/java/docs/reference/google-cloud-contentwarehouse/latest/com.google.cloud.contentwarehouse.v1.DocumentSchema.html#com_google_cloud_contentwarehouse_v1_DocumentSchema_getName__());
        }
      }

      private static String getProjectNumber(String projectId) throws IOException { 
        /* Initialize client that will be used to send requests. 
        * This client only needs to be created once, and can be reused for multiple requests. */
        try (https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html projectsClient = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectsClient.html.create()) { 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html projectName = https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.ProjectName.html.of(projectId); 
          https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html project = projectsClient.getProject(projectName);
          String projectNumber = project.https://docs.cloud.google.com/java/docs/reference/google-cloud-resourcemanager/latest/com.google.cloud.resourcemanager.v3.Project.html#com_google_cloud_resourcemanager_v3_Project_getName__(); // Format returned is projects/xxxxxx
          return projectNumber.substring(projectNumber.lastIndexOf("/") + 1);
        } 
      }
    }

<br />

## Next steps

- Proceed to [Manage documents](https://docs.cloud.google.com/document-warehouse/docs/manage-documents) to learn how to manage documents.