Class v1.DocumentProcessorServiceClient

Service to call Cloud DocumentAI 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. v1

Package

@google-cloud/documentai

Constructors

(constructor)(opts)

constructor(opts?: ClientOptions);

Construct an instance of DocumentProcessorServiceClient.

Parameter
NameDescription
opts ClientOptions

Properties

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

documentProcessorServiceStub

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

innerApiCalls

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

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.

warn

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

Methods

batchProcessDocuments(request, options)

batchProcessDocuments(request?: protos.google.cloud.documentai.v1.IBatchProcessRequest, options?: CallOptions): Promise<[LROperation<protos.google.cloud.documentai.v1.IBatchProcessResponse, protos.google.cloud.documentai.v1.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
NameDescription
request protos.google.cloud.documentai.v1.IBatchProcessRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[LROperation<protos.google.cloud.documentai.v1.IBatchProcessResponse, protos.google.cloud.documentai.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The processor resource name.
   */
  // const name = 'abc123'
  /**
   *  The input documents for batch process.
   */
  // const inputDocuments = {}
  /**
   *  The overall output config for batch process.
   */
  // const documentOutputConfig = {}
  /**
   *  Whether Human Review feature should be skipped for this request. Default to
   *  false.
   */
  // const skipHumanReview = true

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

  // 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.v1.IBatchProcessRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.documentai.v1.IBatchProcessResponse, protos.google.cloud.documentai.v1.IBatchProcessMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.documentai.v1.IBatchProcessRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.documentai.v1.IBatchProcessResponse, protos.google.cloud.documentai.v1.IBatchProcessMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchProcessDocuments(request, callback)

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

checkBatchProcessDocumentsProgress(name)

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

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

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.documentai.v1.BatchProcessResponse, protos.google.cloud.documentai.v1.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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The processor resource name.
   */
  // const name = 'abc123'
  /**
   *  The input documents for batch process.
   */
  // const inputDocuments = {}
  /**
   *  The overall output config for batch process.
   */
  // const documentOutputConfig = {}
  /**
   *  Whether Human Review feature should be skipped for this request. Default to
   *  false.
   */
  // const skipHumanReview = true

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

  // 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();

checkReviewDocumentProgress(name)

checkReviewDocumentProgress(name: string): Promise<LROperation<protos.google.cloud.documentai.v1.ReviewDocumentResponse, protos.google.cloud.documentai.v1.ReviewDocumentOperationMetadata>>;

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

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.documentai.v1.ReviewDocumentResponse, protos.google.cloud.documentai.v1.ReviewDocumentOperationMetadata>>

{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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  An inline document proto.
   */
  // const inlineDocument = {}
  /**
   *  Required. The resource name of the HumanReviewConfig that the document will be
   *  reviewed with.
   */
  // const humanReviewConfig = 'abc123'
  /**
   *  Whether the validation should be performed on the ad-hoc review request.
   */
  // const enableSchemaValidation = true
  /**
   *  The priority of the human review task.
   */
  // const priority = {}

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

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

  async function callReviewDocument() {
    // Construct request
    const request = {
      humanReviewConfig,
    };

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

  callReviewDocument();

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
TypeDescription
Promise<void>

{Promise} A promise that resolves when the client is closed.

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
void

humanReviewConfigPath(project, location, processor)

humanReviewConfigPath(project: string, location: string, processor: string): string;

Return a fully-qualified humanReviewConfig resource name string.

Parameters
NameDescription
project string
location string
processor string
Returns
TypeDescription
string

{string} Resource name string.

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
TypeDescription
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

matchLocationFromHumanReviewConfigName(humanReviewConfigName)

matchLocationFromHumanReviewConfigName(humanReviewConfigName: string): string | number;

Parse the location from HumanReviewConfig resource.

Parameter
NameDescription
humanReviewConfigName string

A fully-qualified path representing HumanReviewConfig resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromProcessorName(processorName)

matchLocationFromProcessorName(processorName: string): string | number;

Parse the location from Processor resource.

Parameter
NameDescription
processorName string

A fully-qualified path representing Processor resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchProcessorFromHumanReviewConfigName(humanReviewConfigName)

matchProcessorFromHumanReviewConfigName(humanReviewConfigName: string): string | number;

Parse the processor from HumanReviewConfig resource.

Parameter
NameDescription
humanReviewConfigName string

A fully-qualified path representing HumanReviewConfig resource.

Returns
TypeDescription
string | number

{string} A string representing the processor.

matchProcessorFromProcessorName(processorName)

matchProcessorFromProcessorName(processorName: string): string | number;

Parse the processor from Processor resource.

Parameter
NameDescription
processorName string

A fully-qualified path representing Processor resource.

Returns
TypeDescription
string | number

{string} A string representing the processor.

matchProjectFromHumanReviewConfigName(humanReviewConfigName)

matchProjectFromHumanReviewConfigName(humanReviewConfigName: string): string | number;

Parse the project from HumanReviewConfig resource.

Parameter
NameDescription
humanReviewConfigName string

A fully-qualified path representing HumanReviewConfig resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromProcessorName(processorName)

matchProjectFromProcessorName(processorName: string): string | number;

Parse the project from Processor resource.

Parameter
NameDescription
processorName string

A fully-qualified path representing Processor resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

processDocument(request, options)

processDocument(request?: protos.google.cloud.documentai.v1.IProcessRequest, options?: CallOptions): Promise<[protos.google.cloud.documentai.v1.IProcessResponse, protos.google.cloud.documentai.v1.IProcessRequest | undefined, {} | undefined]>;

Processes a single document.

Parameters
NameDescription
request protos.google.cloud.documentai.v1.IProcessRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[protos.google.cloud.documentai.v1.IProcessResponse, protos.google.cloud.documentai.v1.IProcessRequest | undefined, {} | undefined]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing [ProcessResponse]. Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  An inline document proto.
   */
  // const inlineDocument = {}
  /**
   *  A raw document content (bytes).
   */
  // const rawDocument = {}
  /**
   *  Required. The processor resource name.
   */
  // const name = 'abc123'
  /**
   *  Whether Human Review feature should be skipped for this request. Default to
   *  false.
   */
  // const skipHumanReview = true

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

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

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

    // Run request
    const response = await documentaiClient.processDocument(request);
    console.log(response);
  }

  callProcessDocument();

processDocument(request, options, callback)

processDocument(request: protos.google.cloud.documentai.v1.IProcessRequest, options: CallOptions, callback: Callback<protos.google.cloud.documentai.v1.IProcessResponse, protos.google.cloud.documentai.v1.IProcessRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.documentai.v1.IProcessRequest
options CallOptions
callback Callback<protos.google.cloud.documentai.v1.IProcessResponse, protos.google.cloud.documentai.v1.IProcessRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

processDocument(request, callback)

processDocument(request: protos.google.cloud.documentai.v1.IProcessRequest, callback: Callback<protos.google.cloud.documentai.v1.IProcessResponse, protos.google.cloud.documentai.v1.IProcessRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.documentai.v1.IProcessRequest
callback Callback<protos.google.cloud.documentai.v1.IProcessResponse, protos.google.cloud.documentai.v1.IProcessRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

processorPath(project, location, processor)

processorPath(project: string, location: string, processor: string): string;

Return a fully-qualified processor resource name string.

Parameters
NameDescription
project string
location string
processor string
Returns
TypeDescription
string

{string} Resource name string.

reviewDocument(request, options)

reviewDocument(request?: protos.google.cloud.documentai.v1.IReviewDocumentRequest, options?: CallOptions): Promise<[LROperation<protos.google.cloud.documentai.v1.IReviewDocumentResponse, protos.google.cloud.documentai.v1.IReviewDocumentOperationMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined]>;

Send a document for Human Review. The input document should be processed by the specified processor.

Parameters
NameDescription
request protos.google.cloud.documentai.v1.IReviewDocumentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[LROperation<protos.google.cloud.documentai.v1.IReviewDocumentResponse, protos.google.cloud.documentai.v1.IReviewDocumentOperationMetadata>, 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](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) for more details and examples.

Example

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  An inline document proto.
   */
  // const inlineDocument = {}
  /**
   *  Required. The resource name of the HumanReviewConfig that the document will be
   *  reviewed with.
   */
  // const humanReviewConfig = 'abc123'
  /**
   *  Whether the validation should be performed on the ad-hoc review request.
   */
  // const enableSchemaValidation = true
  /**
   *  The priority of the human review task.
   */
  // const priority = {}

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

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

  async function callReviewDocument() {
    // Construct request
    const request = {
      humanReviewConfig,
    };

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

  callReviewDocument();

reviewDocument(request, options, callback)

reviewDocument(request: protos.google.cloud.documentai.v1.IReviewDocumentRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.documentai.v1.IReviewDocumentResponse, protos.google.cloud.documentai.v1.IReviewDocumentOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.documentai.v1.IReviewDocumentRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.documentai.v1.IReviewDocumentResponse, protos.google.cloud.documentai.v1.IReviewDocumentOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

reviewDocument(request, callback)

reviewDocument(request: protos.google.cloud.documentai.v1.IReviewDocumentRequest, callback: Callback<LROperation<protos.google.cloud.documentai.v1.IReviewDocumentResponse, protos.google.cloud.documentai.v1.IReviewDocumentOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request protos.google.cloud.documentai.v1.IReviewDocumentRequest
callback Callback<LROperation<protos.google.cloud.documentai.v1.IReviewDocumentResponse, protos.google.cloud.documentai.v1.IReviewDocumentOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void