-3

I try to implement the document AI API to be able to compare a document to see if it comes with phrases to know if the document is valid.

I am using nodejs to implement the document AI API, and the document I receive is a PDF that is sent through an input file

This is the error that I get:

Error: Error: 3 INVALID_ARGUMENT: Invalid resource field value in the request.

{
  code: 3,
  details: 'Invalid resource field value in the request.',
  metadata: Metadata {
    internalRepr: Map(4) {
      'endpoint-load-metrics-bin' => [Array],
      'grpc-server-stats-bin' => [Array],
      'google.rpc.errorinfo-bin' => [Array],
      'grpc-status-details-bin' => [Array]
    },
    options: {}
  },
  note: 'Exception occurred in retry method that was not classified as transient',
  statusDetails: [
    ErrorInfo {
      metadata: [Object],
      reason: 'RESOURCE_PROJECT_INVALID',
      domain: 'googleapis.com'
    }
  ],
  reason: 'RESOURCE_PROJECT_INVALID',
  domain: 'googleapis.com',
  errorInfoMetadata: {
    service: 'documentai.googleapis.com',
    method: 'google.cloud.documentai.v1.DocumentProcessorService.ProcessDocument'
  }
}

This is the code in nodejs that I use to authenticate myself and to make the comparison, I hope you can help me.

//documentAI

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

const keyFilename = path.join(__dirname,"../../src/credentials/documentApp.json");

// Configuración del cliente de Document AI
const client = new DocumentProcessorServiceClient({
  keyFilename: keyFilename,
});

async function procesarDocumentoConAI(document) {
    try {
        const request = {
            parent: 'projects/c26b6829b968a72c/locations/us',
            processorId:'c26b6829b968a72c',
            inputConfig: {
                content: document,
                mimeType: 'application/pdf',
              },
          };

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

        if (response && response.text) {
            const text = response.text;
            const isINE = text.includes('INE') || text.includes('Instituto Nacional Electoral');

            if (isINE) {
                console.log('El documento contiene una INE mexicana.');
                return true;
            } else {
                console.log('El documento no contiene una INE mexicana.');
                return false;
            }
        } else {
            console.log('No se encontró texto en el documento.');
            return false;
        }
    } catch (error) {
        console.error('Error:', error);
    }
}

1 Answer 1

0

In your request, you are sending the processor ID as the project ID. You need to change it to be the project ID.

parent: 'projects/c26b6829b968a72c/locations/us',

c26b6829b968a72c is your Processor ID, this value should be changed to your project ID.

You can read how to find your project ID in this article.

https://cloud.google.com/resource-manager/docs/creating-managing-projects

Your request also isn't using the correct structure. You can find Node.JS sample code for making a processing request and information about how requests work on this page.

https://cloud.google.com/document-ai/docs/process-documents-client-libraries#client-libraries-install-nodejs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.