DocumentError "Permission 'documentai.processors.processOnline' denied on resource 'my processors' (or it may not exist)

Viewed 468

im trying to implement documentai with NodeJS

and im stuck while trying to run DocumentProcessorServiceClient()

i got this error

    Error: 7 PERMISSION_DENIED: Permission 'documentai.processors.processOnline' denied on resource '//documentai.googleapis.com/projects/<project-id>/locations/us/processors/<processor-id>' (or it may not exist).
      at Object.callErrorFromStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
      at Object.onReceiveStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\client.js:176:52)
      at Object.onReceiveStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:336:141)
      at Object.onReceiveStatus (C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
      at C:\Users\dev\me-ocr\node_modules\@grpc\grpc-js\build\src\call-stream.js:130:78 
      at processTicksAndRejections (internal/process/task_queues.js:79:11) {
    code: 7,
    details: "Permission 'documentai.processors.processOnline' denied on resource '//documentai.googleapis.com/projects/<project-id>/locations/us/processors/<processor-id>' (or it may not exist).",
    metadata: Metadata { internalRepr: [Map], options: {} },
    note: 'Exception occurred in retry method that was not classified as transient'
  }

here is my function

const doScan = async (filePath: string) => {
  try {
    // Configure the request for processing the PDF
    const name = `projects/${projectId}/locations/${location}/processors/${processorId}`; 
    // Read the file into memory.
    const imageFile = await fs.promises.readFile(filePath); 
    // Convert the image data to a Buffer and base64 encode it.
    const encodedImage = Buffer.from(imageFile).toString("base64"); 
    const request = {
      name,
      document: {
        content: encodedImage,
        mimeType: "application/pdf",
      },
    };   
    // Recognizes text entities in the PDF document
    const [result] = await client.processDocument(request);  
    const { document }: any = result;
    const { text }: any = document;
    const getText = (textAnchor: any) => {
      if (!textAnchor.textSegments || textAnchor.textSegments.length === 0) {
        return "";
      } 
      // First shard in document doesn't have startIndex property
      const startIndex = textAnchor.textSegments[0].startIndex || 0;
      const endIndex = textAnchor.textSegments[0].endIndex; 
      return text.substring(startIndex, endIndex);
    }; 
    // Read the text recognition output from the processor
    console.log("The document contains the following paragraphs:");
    const [page1] = document.pages;
    const { paragraphs } = page1;

    for (const paragraph of paragraphs) {
      const paragraphText = getText(paragraph.layout.textAnchor);
      console.log(`Paragraph text:\n${paragraphText}`);
    }
  } catch (err) {
    console.log({ err });
  }
};

i've already try change the name using this, but it ends the same... client.processorPath(projectId, location, processorId);

Thanks

0 Answers
Related