Fetch processor types (v1)

Fetch available processor types for a specific project and location.

Code sample

Java

For more information, see the Document AI Java API reference documentation.

To authenticate to Document AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.DocumentProcessorServiceSettings;
import com.google.cloud.documentai.v1.FetchProcessorTypesRequest;
import com.google.cloud.documentai.v1.FetchProcessorTypesResponse;
import com.google.cloud.documentai.v1.ProcessorType;
import java.io.IOException;

public class FetchProcessorTypes {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project-id";
    String locationId = "us";
    fetchProcessorTypes(projectId, locationId);
  }

  public static void fetchProcessorTypes(String projectId, String locationId) throws Exception {
    // Configure the client to connect to the regional endpoint.
    String endpoint = String.format("%s-documentai.googleapis.com:443", locationId);
    DocumentProcessorServiceSettings settings =
        DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();

    try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
      String parent = String.format("projects/%s/locations/%s", projectId, locationId);
      FetchProcessorTypesRequest request =
          FetchProcessorTypesRequest.newBuilder().setParent(parent).build();

      FetchProcessorTypesResponse response = client.fetchProcessorTypes(request);

      for (ProcessorType processorType : response.getProcessorTypesList()) {
        System.out.printf("Processor Type: %s%n", processorType.getType());
        System.out.printf("Category: %s%n", processorType.getCategory());
        System.out.printf("Allow Creation: %b%n", processorType.getAllowCreation());
      }
    }
  }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.