예제 #1
0
        public SupplierInvoiceApi GetSingleSupplierInvoice(string accessToken)
        {
            var jss             = new JavaScriptSerializer();
            var supplierInvoice = new SupplierInvoiceApi();

            using (var client = new WebClient())
            {
                //Encode...
                client.Encoding = Encoding.UTF8;

                //Define content type
                client.Headers[HttpRequestHeader.ContentType] =
                    "application/json";

                //Define auth header
                client.Headers[HttpRequestHeader.Authorization] =
                    $"Bearer {accessToken}";

                //Call api and save response
                // Here are a few Id's of existing invoices that you can pass in the request.
                // a31d5f22-0c1b-40ff-be0b-6228fcb87986
                // 3e598116-58ab-4780-a040-7b23de47c347
                // b6e31c41-279b-4f06-841f-5505b548eddc
                var response = client.DownloadString($"{supplierInvoiceUri}/a31d5f22-0c1b-40ff-be0b-6228fcb87986");


                //Convert response to Datamodel
                supplierInvoice = jss.Deserialize <SupplierInvoiceApi>(response);
            }

            return(supplierInvoice);
        }
예제 #2
0
        public string ValidateInvoice(SupplierInvoiceApi invoice)
        {
            var jss = new JavaScriptSerializer();

            using (var client = new WebClient())
            {
                //Encode...
                client.Encoding = Encoding.UTF8;

                //Define content type
                client.Headers[HttpRequestHeader.ContentType] =
                    "application/json";

                //Define auth header
                client.Headers[HttpRequestHeader.Authorization] =
                    $"Bearer {apiKey}";



                MachineLearningDto requestBody = new MachineLearningDto();
                requestBody.Inputs.input1.ColumnNames = new List <string>
                {
                    "supplier_name",
                    "invoice_date",
                    "due_date",
                    "invoice_number",
                    "total_amount",
                    "vat",
                    "currency_code",
                    "ocr_number",
                    "message",
                    "bank_giro",
                    "is_fake"
                };


                var values = new List <string>
                {
                    invoice.SupplierName,
                    invoice.InvoiceDate,
                    invoice.DueDate,
                    invoice.InvoiceNumber,
                    invoice.TotalAmount.ToString(),
                    invoice.Vat.ToString(),
                    invoice.CurrencyCode,
                    invoice.OcrNumber,
                    invoice.Message,
                    invoice.BankGiroNumber,
                    "false"
                };

                requestBody.Inputs.input1.Values = new List <List <string> >();
                requestBody.Inputs.input1.Values.Add(values);

                var    serializedRequestBody = jss.Serialize(requestBody);
                string response = "";

                Console.WriteLine(serializedRequestBody);

                try
                {
                    response = client.UploadString(requestUri, serializedRequestBody);
                }
                catch (WebException e)
                {
                    Console.WriteLine(e.Message);
                }

                return(response);
            }
        }