Demo 2: C#

An example of how to call the document verification crop endpoint using C#

    using System;
    using System.IO;
    using System.Net.Http;
    using System.Threading.Tasks;
    using Newtonsoft.Json;

    public class Program
    {
        public class CropResult
        {
            public string Image { get; set; }
        }

        static async Task Main(string[] args)
        {
            var client = new HttpClient();

            var content = new MultipartFormDataContent();

            content.Add(new ByteArrayContent(File.ReadAllBytes("/ID1-Page1.png")), "Image", "image.png");

            content.Add(new StringContent("Id1"), "DocumentType");

            content.Add(new StringContent("1"), "Page");

            var response = await client.SendAsync(new HttpRequestMessage
            {
                Method = HttpMethod.Post,
                Headers = { { "Authorization", "Basic YourApiKey" } },
                RequestUri = new Uri("https://api.w2globaldata.com/document-verification/crop?api=version=1.1"),
                Content = content
            });

            var cropResult = JsonConvert.DeserializeObject<CropResult>(
                await response.Content.ReadAsStringAsync());

            File.WriteAllBytes("id1-cropped.png", Convert.FromBase64String(cropResult.Image));

            Console.WriteLine("Cropped image saved");

            Console.ReadLine();
        }
    }