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);
}
}