简体   繁体   中英

Cloud Document AI API has not been used in project xxxxxx before or it is disabled

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

在此处输入图像描述

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

在此处输入图像描述

final fix在此处输入图像描述

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在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM