1

I am very new in google Document AI, I tried to use this code but still have this response. Do you have any idea what I'm doing wrong? I have installed from nuget Google.Cloud.DocumentAI.V1

Status(StatusCode="InvalidArgument", Detail="Request contains an invalid argument.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1643889903.765000000","description":"Error received from peer ipv4:142.250.186.42:443","file":"......\src\core\lib\surface\call.cc","file_line":1067,"grpc_message":"Request contains an invalid argument.","grpc_status":3}")

    public async void Start()
    {
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"path-to-json");

        try
        {
            //Generate a document
            string pdfFilePath = @"path-to-invoice-pdf";
            var bytes = File.ReadAllBytes(pdfFilePath);
            ByteString content = ByteString.CopyFrom(bytes);

            // Create client
            DocumentProcessorServiceClient documentProcessorServiceClient = await DocumentProcessorServiceClient.CreateAsync();
            // Initialize request argument(s)

            ProcessRequest request = new ProcessRequest
            {
                ProcessorName = ProcessorName.FromProjectLocationProcessor("ProjectID", "eu", "ProcessorID"),
                SkipHumanReview = false,
                RawDocument = new RawDocument
                {
                    MimeType = "application/pdf",
                    Content = content
                }
            };



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

            Document docResponse = response.Document;

            Console.WriteLine(docResponse.Text);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }


    }
Viktor Fodor
  • 55
  • 1
  • 8
  • You have to set the parameter “apiEndpoint” when your location is not "us". Refer to this similar [thread](https://stackoverflow.com/a/66765483/15747106) and let me know if it helps? – Vishal K Feb 04 '22 at 15:28
  • Hi Vishal, yeah your are true. In US processor it is working correctly, but for EU is this error.. BUT I can not find where can I set apiEndpoint. – Viktor Fodor Feb 04 '22 at 15:31
  • Hi Viktor, I have posted the answer. – Vishal K Feb 08 '22 at 18:38

1 Answers1

1

Quoted from this doc:

Note that if you wish to use DocumentProcessorServiceClient other than in the US, you must specify the endpoint when you construct the client. The endpoint is of the form {location}-documentai.googleapis.com, e.g. eu-documentai.googleapis.com. The simplest way to specify the endpoint is to use DocumentProcessorServiceClientBuilder:

DocumentProcessorServiceClient client = new DocumentProcessorServiceClientBuilder
{
    Endpoint = "eu-documentai.googleapis.com"
}.Build();

Vishal K
  • 1,368
  • 1
  • 7
  • 15
  • Correct, this has been updated/clarified in the documentation. https://cloud.google.com/document-ai/docs/send-request – Holt Skinner Aug 04 '22 at 19:50