Class v1beta3.DocumentProcessorServiceClient (8.12.0)

Service to call Document AI to process documents according to the processor's definition. Processors are built using state-of-the-art Google AI such as natural language, computer vision, and translation to extract structured information from unstructured or semi-structured documents. v1beta3

Package

@google-cloud/documentai

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of DocumentProcessorServiceClient.

Parameters
Name Description
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new DocumentProcessorServiceClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

documentProcessorServiceStub

documentProcessorServiceStub?: Promise<{
        [name: string]: Function;
    }>;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

locationsClient

locationsClient: LocationsClient;

operationsClient

operationsClient: gax.OperationsClient;

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

universeDomain

get universeDomain(): string;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

batchProcessDocuments(request, options)

batchProcessDocuments(request?: protos.google.cloud.documentai.v1beta3.IBatchProcessRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.cloud.documentai.v1beta3.IBatchProcessResponse, protos.google.cloud.documentai.v1beta3.IBatchProcessMetadata>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

LRO endpoint to batch process many documents. The output is written to Cloud Storage as JSON in the [Document] format.

Parameters
Name Description
request IBatchProcessRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ LROperation<protos.google.cloud.documentai.v1beta3.IBatchProcessResponse, protos.google.cloud.documentai.v1beta3.IBatchProcessMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of
   *  Processor google.cloud.documentai.v1beta3.Processor  or
   *  ProcessorVersion google.cloud.documentai.v1beta3.ProcessorVersion.
   *  Format: `projects/{project}/locations/{location}/processors/{processor}`,
   *  or
   *  `projects/{project}/locations/{location}/processors/{processor}/processorVersions/{processorVersion}`
   */
  // const name = 'abc123'
  /**
   *  The input config for each single document in the batch process.
   */
  // const inputConfigs = [1,2,3,4]
  /**
   *  The overall output config for batch process.
   */
  // const outputConfig = {}
  /**
   *  The input documents for the
   *  BatchProcessDocuments google.cloud.documentai.v1beta3.DocumentProcessorService.BatchProcessDocuments 
   *  method.
   */
  // const inputDocuments = {}
  /**
   *  The output configuration for the
   *  BatchProcessDocuments google.cloud.documentai.v1beta3.DocumentProcessorService.BatchProcessDocuments 
   *  method.
   */
  // const documentOutputConfig = {}
  /**
   *  Whether human review should be skipped for this request. Default to
   *  `false`.
   */
  // const skipHumanReview = true
  /**
   *  Inference-time options for the process API
   */
  // const processOptions = {}
  /**
   *  Optional. The labels with user-defined metadata for the request.
   *  Label keys and values can be no longer than 63 characters
   *  (Unicode codepoints) and can only contain lowercase letters, numeric
   *  characters, underscores, and dashes. International characters are allowed.
   *  Label values are optional. Label keys must start with a letter.
   */
  // const labels = [1,2,3,4]

  // Imports the Documentai library
  const {DocumentProcessorServiceClient} = require('@google-cloud/documentai').v1beta3;

  // Instantiates a client
  const documentaiClient = new DocumentProcessorServiceClient();

  async function callBatchProcessDocuments() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await documentaiClient.batchProcessDocuments(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callBatchProcessDocuments();

batchProcessDocuments(request, options, callback)

batchProcessDocuments(request: protos.google.cloud.documentai.v1beta3.IBatchProcessRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchProcessResponse, protos.google.cloud.documentai.v1beta3.IBatchProcessMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IBatchProcessRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchProcessResponse, protos.google.cloud.documentai.v1beta3.IBatchProcessMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
Type Description
void

batchProcessDocuments(request, callback)

batchProcessDocuments(request: protos.google.cloud.documentai.v1beta3.IBatchProcessRequest, callback: Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchProcessResponse, protos.google.cloud.documentai.v1beta3.IBatchProcessMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IBatchProcessRequest
callback Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchProcessResponse, protos.google.cloud.documentai.v1beta3.IBatchProcessMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
Type Description
void

cancelOperation(request, options, callback)

cancelOperation(request: protos.google.longrunning.CancelOperationRequest, options?: gax.CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.CancelOperationRequest, {} | undefined | null>, callback?: Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>): Promise<protos.google.protobuf.Empty>;

Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED. Clients can use or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an value with a of 1, corresponding to Code.CANCELLED.

Parameters
Name Description
request CancelOperationRequest

The request object that will be sent.

options CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.CancelOperationRequest, {} | undefined | null>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>

The function which will be called with the result of the API call. {Promise} - The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Returns
Type Description
Promise<protos.google.protobuf.Empty>
Example

const client = longrunning.operationsClient();
await client.cancelOperation({name: ''});

checkBatchProcessDocumentsProgress(name)

checkBatchProcessDocumentsProgress(name: string): Promise<LROperation<protos.google.cloud.documentai.v1beta3.BatchProcessResponse, protos.google.cloud.documentai.v1beta3.BatchProcessMetadata>>;

Check the status of the long running operation returned by batchProcessDocuments().

Parameter
Name Description
name string

The operation name that will be passed.

Returns
Type Description
Promise<LROperation<protos.google.cloud.documentai.v1beta3.BatchProcessResponse, protos.google.cloud.documentai.v1beta3.BatchProcessMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of
   *  Processor google.cloud.documentai.v1beta3.Processor  or
   *  ProcessorVersion google.cloud.documentai.v1beta3.ProcessorVersion.
   *  Format: `projects/{project}/locations/{location}/processors/{processor}`,
   *  or
   *  `projects/{project}/locations/{location}/processors/{processor}/processorVersions/{processorVersion}`
   */
  // const name = 'abc123'
  /**
   *  The input config for each single document in the batch process.
   */
  // const inputConfigs = [1,2,3,4]
  /**
   *  The overall output config for batch process.
   */
  // const outputConfig = {}
  /**
   *  The input documents for the
   *  BatchProcessDocuments google.cloud.documentai.v1beta3.DocumentProcessorService.BatchProcessDocuments 
   *  method.
   */
  // const inputDocuments = {}
  /**
   *  The output configuration for the
   *  BatchProcessDocuments google.cloud.documentai.v1beta3.DocumentProcessorService.BatchProcessDocuments 
   *  method.
   */
  // const documentOutputConfig = {}
  /**
   *  Whether human review should be skipped for this request. Default to
   *  `false`.
   */
  // const skipHumanReview = true
  /**
   *  Inference-time options for the process API
   */
  // const processOptions = {}
  /**
   *  Optional. The labels with user-defined metadata for the request.
   *  Label keys and values can be no longer than 63 characters
   *  (Unicode codepoints) and can only contain lowercase letters, numeric
   *  characters, underscores, and dashes. International characters are allowed.
   *  Label values are optional. Label keys must start with a letter.
   */
  // const labels = [1,2,3,4]

  // Imports the Documentai library
  const {DocumentProcessorServiceClient} = require('@google-cloud/documentai').v1beta3;

  // Instantiates a client
  const documentaiClient = new DocumentProcessorServiceClient();

  async function callBatchProcessDocuments() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await documentaiClient.batchProcessDocuments(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callBatchProcessDocuments();

checkDeleteProcessorProgress(name)

checkDeleteProcessorProgress(name: string): Promise<LROperation<protos.google.protobuf.Empty, protos.google.cloud.documentai.v1beta3.DeleteProcessorMetadata>>;

Check the status of the long running operation returned by deleteProcessor().

Parameter
Name Description
name string

The operation name that will be passed.

Returns
Type Description
Promise<LROperation<protos.google.protobuf.Empty, protos.google.cloud.documentai.v1beta3.DeleteProcessorMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The processor resource name to be deleted.
   */