0

While calling google document api, getting below error. apis are enabled, even after waiting for few hours still getting same error. any suggestion

RpcException: Status(StatusCode="PermissionDenied", Detail="Cloud Document AI API has not been used in project xxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/documentai.googleapis.com/overview?project=xxxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1646997388.673000000","description": "Error received from peer ipv4:234.234324.324234:443","file":"......\src\core\lib\surface\call.cc","file_line":1070,"grpc_message": "Cloud Document AI API has not been used in project xxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/documentai.googleapis.com/overview?project=xxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","grpc_status":7}")

 ByteString content = ByteString.CopyFrom(bytes);

            DocumentProcessorServiceClient documentProcessorServiceClient = new DocumentProcessorServiceClientBuilder
            { CredentialsPath = "D:\\poised-aleph-3xx-6a3xxxx4343a03.json" }
            .Build();

            ProcessRequest request = new ProcessRequest
            {
                ProcessorName = ProcessorName.FromProjectLocationProcessor("invoiceprocessor", "us", "343431"),
                SkipHumanReview = true,
                RawDocument = new RawDocument
                {
                    MimeType = "application/pdf",
                    Content = content
                }
            };

            request.RawDocument.MimeType = "application/pdf";
            request.RawDocument.Content = content;

            // Make the request
            ProcessResponse response = await 
 documentProcessorServiceClient.ProcessDocumentAsync(request);

after fixing correct project id, as shown in developer console -> Prediction endpoint

enter image description here

Detail="Permission 'documentai.processors.processOnline' denied on resource 
'//documentai.googleapis.com/projects/8xxxxxxxx7/locations/us/processors/axxxxxxxxxx1f' (or it may not exist)."

Adding Document AI Role to service account

enter image description here

final fix enter image description here

anand
  • 307
  • 3
  • 14
  • invalid project id used. now this error doesnt appear, but still service failing. – anand Mar 14 '22 at 05:30
  • endpoint : https://us-documentai.googleapis.com/v1/projects/xxxx/locations/us/processors/xxxxx:process documentclient api throws this error. RpcException: Status(StatusCode="PermissionDenied", Detail="Permission 'documentai.processors.processOnline' denied on resource '//documentai.googleapis.com/projects/xxxx/locations/us/processors/xxxxxx' (or it may not exist)." ProjectId, processorId matching with endpointurl in console. – anand Mar 14 '22 at 05:31
  • Hi OP, can you validate that you are using the correct project ID as mentioned by @anand on the above comment? – Scott B Mar 14 '22 at 05:54
  • @ScottB, projectid, processorid shown in console->predictionendpoint is used in clientapi. – anand Mar 14 '22 at 06:14
  • @ScottB updated original post with recent error details. – anand Mar 14 '22 at 06:32

1 Answers1

1

Since @anand (OP) has already fixed the first issue as mentioned on the above updated question, OP got the below recent error

RpcException: Status(StatusCode="PermissionDenied", Detail="Permission 'documentai.processors.processOnline' denied on resource 
'//documentai.googleapis.com/projects/xxxx/locations/us/processors/xxxxxx' (or it may not exist)."

This error is related on the permission of the service account being used to authenticate the API.

You may update your Serivce Account permission by navigating to IAM & Admin > IAM enter image description here

You may navigate on the list and edit the permission of your service account from that page. You may follow this documentation on how to setup service account authentication for Document AI.

Since your error message shows that you are having issues on documentai.processors.processOnline, you may grant the Cloud DocumentAI API User role to your service account since it has below permissions which also covered the one on your error message:

documentai.operations.getLegacy, documentai.processors.processOnline, documentai.processors.processBatch.

You may also refer to this Document AI IAM Roles Documentation for more information on the pre-defined roles for Document AI.

Scott B
  • 2,516
  • 1
  • 8
  • 15
  • added documentai api user role to service account. (screenshot attached in OP). and generated new key as well. But still getting "StatusCode="PermissionDenied", Detail="Permission 'documentai.processors.processOnline' denied on resource" error. – anand Mar 14 '22 at 10:29
  • it works after providing document api user role to client_email specified in Json. thanks – anand Mar 14 '22 at 11:03
  • @anand, I think you granted your own user the Cloud Document AI API User on your first try instead of the actual service account. A service account is a non-human user that needs to authenticate and be authorized to access data in Google APIs. You mat check out https://cloud.google.com/iam/docs/understanding-service-accounts#background to know more about service accounts. – Scott B Mar 15 '22 at 00:44
  • thanks @scottb. it works and updated my OP and marked this as anwer. thanks. – anand Mar 15 '22 at 05:32