Class v1beta3.DocumentServiceClient (8.2.0)

Service to call Cloud DocumentAI to manage document collection (dataset). v1beta3

Package

@google-cloud/documentai

Constructors

(constructor)(opts, gaxInstance)

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

Construct an instance of DocumentServiceClient.

Parameters
NameDescription
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 DocumentServiceClient({fallback: true}, gax); ```

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;

documentServiceStub

documentServiceStub?: 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.

warn

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

Methods

batchDeleteDocuments(request, options)

batchDeleteDocuments(request?: protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsMetadata>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Deletes a set of documents.

Parameters
NameDescription
request IBatchDeleteDocumentsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ LROperation<protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsMetadata>, 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 dataset resource name.
   *  Format:
   *  projects/{project}/locations/{location}/processors/{processor}/dataset
   */
  // const dataset = 'abc123'
  /**
   *  Required. Dataset documents input. If given `filter`, all documents
   *  satisfying the filter will be deleted. If given documentIds, a maximum of
   *  50 documents can be deleted in a batch. The request will be rejected if
   *  more than 50 document_ids are provided.
   */
  // const datasetDocuments = {}

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

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

  async function callBatchDeleteDocuments() {
    // Construct request
    const request = {
      dataset,
      datasetDocuments,
    };

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

  callBatchDeleteDocuments();

batchDeleteDocuments(request, options, callback)

batchDeleteDocuments(request: protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IBatchDeleteDocumentsRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchDeleteDocuments(request, callback)

batchDeleteDocuments(request: protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsRequest, callback: Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IBatchDeleteDocumentsRequest
callback Callback<LROperation<protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.IBatchDeleteDocumentsMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
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
NameDescription
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
TypeDescription
Promise<protos.google.protobuf.Empty>
Example

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

checkBatchDeleteDocumentsProgress(name)

checkBatchDeleteDocumentsProgress(name: string): Promise<LROperation<protos.google.cloud.documentai.v1beta3.BatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.BatchDeleteDocumentsMetadata>>;

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

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.documentai.v1beta3.BatchDeleteDocumentsResponse, protos.google.cloud.documentai.v1beta3.BatchDeleteDocumentsMetadata>>

{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 dataset resource name.
   *  Format:
   *  projects/{project}/locations/{location}/processors/{processor}/dataset
   */
  // const dataset = 'abc123'
  /**
   *  Required. Dataset documents input. If given `filter`, all documents
   *  satisfying the filter will be deleted. If given documentIds, a maximum of
   *  50 documents can be deleted in a batch. The request will be rejected if
   *  more than 50 document_ids are provided.
   */
  // const datasetDocuments = {}

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

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

  async function callBatchDeleteDocuments() {
    // Construct request
    const request = {
      dataset,
      datasetDocuments,
    };

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

  callBatchDeleteDocuments();

checkImportDocumentsProgress(name)

checkImportDocumentsProgress(name: string): Promise<LROperation<protos.google.cloud.documentai.v1beta3.ImportDocumentsResponse, protos.google.cloud.documentai.v1beta3.ImportDocumentsMetadata>>;

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

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.documentai.v1beta3.ImportDocumentsResponse, protos.google.cloud.documentai.v1beta3.ImportDocumentsMetadata>>

{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 dataset resource name.
   *  Format:
   *  projects/{project}/locations/{location}/processors/{processor}/dataset
   */
  // const dataset = 'abc123'
  /**
   *  Required. The Cloud Storage uri containing raw documents that must be
   *  imported.
   */
  // const batchDocumentsImportConfigs = [1,2,3,4]

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

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

  async function callImportDocuments() {
    // Construct request
    const request = {
      dataset,
      batchDocumentsImportConfigs,
    };

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

  callImportDocuments();

checkUpdateDatasetProgress(name)

checkUpdateDatasetProgress(name: string): Promise<LROperation<protos.google.cloud.documentai.v1beta3.Dataset, protos.google.cloud.documentai.v1beta3.UpdateDatasetOperationMetadata>>;

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

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.documentai.v1beta3.Dataset, protos.google.cloud.documentai.v1beta3.UpdateDatasetOperationMetadata>>

{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 `name` field of the `Dataset` is used to identify the
   *  resource to be updated.
   */
  // const dataset = {}
  /**
   *  The update mask applies to the resource.
   */
  // const updateMask = {}

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

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

  async function callUpdateDataset() {
    // Construct request
    const request = {
      dataset,
    };

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

  callUpdateDataset();

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.

datasetPath(project, location, processor)

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

Return a fully-qualified dataset resource name string.

Parameters
NameDescription
project string
location string
processor string
Returns
TypeDescription
string

{string} Resource name string.

datasetSchemaPath(project, location, processor)

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

Return a fully-qualified datasetSchema resource name string.

Parameters
NameDescription
project string
location string
processor string
Returns
TypeDescription
string

{string} Resource name string.

deleteOperation(request, options, callback)

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

Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED.

Parameters
NameDescription
request DeleteOperationRequest

The request object that will be sent.

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

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.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>

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
TypeDescription
Promise<protos.google.protobuf.Empty>
Example

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

evaluationPath(project, location, processor, processorVersion, evaluation)

evaluationPath(project: string, location: string, processor: string, processorVersion: string, evaluation: string): string;

Return a fully-qualified evaluation resource name string.

Parameters
NameDescription
project string
location string
processor string
processorVersion string
evaluation string
Returns
TypeDescription
string

{string} Resource name string.

getDatasetSchema(request, options)

getDatasetSchema(request?: protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest, options?: CallOptions): Promise<[
        protos.google.cloud.documentai.v1beta3.IDatasetSchema,
        (protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest | undefined),
        {} | undefined
    ]>;

Gets the DatasetSchema of a Dataset.

Parameters
NameDescription
request IGetDatasetSchemaRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.documentai.v1beta3.IDatasetSchema, (protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest | undefined), {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing DatasetSchema. 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 dataset schema resource name.
   *  Format:
   *  projects/{project}/locations/{location}/processors/{processor}/dataset/datasetSchema
   */
  // const name = 'abc123'
  /**
   *  If set, only returns the visible fields of the schema.
   */
  // const visibleFieldsOnly = true

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

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

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

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

  callGetDatasetSchema();

getDatasetSchema(request, options, callback)

getDatasetSchema(request: protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest, options: CallOptions, callback: Callback<protos.google.cloud.documentai.v1beta3.IDatasetSchema, protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetDatasetSchemaRequest
options CallOptions
callback Callback<protos.google.cloud.documentai.v1beta3.IDatasetSchema, protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getDatasetSchema(request, callback)

getDatasetSchema(request: protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest, callback: Callback<protos.google.cloud.documentai.v1beta3.IDatasetSchema, protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetDatasetSchemaRequest
callback Callback<protos.google.cloud.documentai.v1beta3.IDatasetSchema, protos.google.cloud.documentai.v1beta3.IGetDatasetSchemaRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getDocument(request, options)

getDocument(request?: protos.google.cloud.documentai.v1beta3.IGetDocumentRequest, options?: CallOptions): Promise<[
        protos.google.cloud.documentai.v1beta3.IGetDocumentResponse,
        protos.google.cloud.documentai.v1beta3.IGetDocumentRequest | undefined,
        {} | undefined
    ]>;

Returns relevant fields present in the requested document.

Parameters
NameDescription
request IGetDocumentRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.documentai.v1beta3.IGetDocumentResponse, protos.google.cloud.documentai.v1beta3.IGetDocumentRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing GetDocumentResponse. 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 the dataset that the document belongs to .
   *  Format:
   *  projects/{project}/locations/{location}/processors/{processor}/dataset
   */
  // const dataset = 'abc123'
  /**
   *  Required. Document identifier.
   */
  // const documentId = {}
  /**
   *  If set, only fields listed here will be returned. Otherwise, all fields
   *  will be returned by default.
   */
  // const readMask = {}
  /**
   *  List of pages for which the fields specified in the `read_mask` must
   *  be served.
   */
  // const pageRange = {}

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

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

  async function callGetDocument() {
    // Construct request
    const request = {
      dataset,
      documentId,
    };

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

  callGetDocument();

getDocument(request, options, callback)

getDocument(request: protos.google.cloud.documentai.v1beta3.IGetDocumentRequest, options: CallOptions, callback: Callback<protos.google.cloud.documentai.v1beta3.IGetDocumentResponse, protos.google.cloud.documentai.v1beta3.IGetDocumentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetDocumentRequest
options CallOptions
callback Callback<protos.google.cloud.documentai.v1beta3.IGetDocumentResponse, protos.google.cloud.documentai.v1beta3.IGetDocumentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getDocument(request, callback)

getDocument(request: protos.google.cloud.documentai.v1beta3.IGetDocumentRequest, callback: Callback<protos.google.cloud.documentai.v1beta3.IGetDocumentResponse, protos.google.cloud.documentai.v1beta3.IGetDocumentRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetDocumentRequest
callback Callback<protos.google.cloud.documentai.v1beta3.IGetDocumentResponse, protos.google.cloud.documentai.v1beta3.IGetDocumentRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getLocation(request, options, callback)

getLocation(request: LocationProtos.google.cloud.location.IGetLocationRequest, options?: gax.CallOptions | Callback<LocationProtos.google.cloud.location.ILocation, LocationProtos.google.cloud.location.IGetLocationRequest | null | undefined, {} | null | undefined>, callback?: Callback<LocationProtos.google.cloud.location.ILocation, LocationProtos.google.cloud.location.IGetLocationRequest | null | undefined, {} | null | undefined>): Promise<LocationProtos.google.cloud.location.ILocation>;

Gets information about a location.

Parameters
NameDescription
request LocationProtos.google.cloud.location.IGetLocationRequest

The request object that will be sent.

options CallOptions | Callback<google.cloud.location.ILocation, google.cloud.location.IGetLocationRequest | null | undefined, {} | null | undefined>

Call options. See CallOptions for more details.

callback Callback<google.cloud.location.ILocation, google.cloud.location.IGetLocationRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
Promise<google.cloud.location.ILocation>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the documentation for more details and examples.

Example

const [response] = await client.getLocation(request);

getOperation(request, options, callback)

getOperation(request: protos.google.longrunning.GetOperationRequest, options?: gax.CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>): Promise<[protos.google.longrunning.Operation]>;

Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service.

Parameters
NameDescription
request GetOperationRequest

The request object that will be sent.

options CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>

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.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing . {Promise} - The promise which resolves to an array. The first element of the array is an object representing . The promise has a method named "cancel" which cancels the ongoing API call.

Returns
TypeDescription
Promise<[protos.google.longrunning.Operation]>
Example

const client = longrunning.operationsClient();
const name = '';
const [response] = await client.getOperation({name});
// doThingsWith(response)

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

importDocuments(request, options)

importDocuments(request?: protos.google.cloud.documentai.v1beta3.IImportDocumentsRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.cloud.documentai.v1beta3.IImportDocumentsResponse, protos.google.cloud.documentai.v1beta3.IImportDocumentsMetadata>,
        protos.google.longrunning.IOperation