Below is an end-to-end example of submitting a Merge request using C# programming language:


// Simple script to showcasing how to use the Merge API in the LEADTOOLS Cloud Services.
// In order to run this program, the following changes will need to be added:
//	1) Place your Application ID in the AppId variable in the InitClient method.
//	2) Place your Application Password in the Password variable in the InitClient method.
//
// The program will perform the following operations in order:
//	  1) Upload 2 files to the LEADTOOLS Cloud Services using the forMerge flag.
//   2) Make a call to the Merge end-point to combine the two files.
//   3) Parse the JSON output from the LEADTOOLS Cloud Services

// This program makes use of the following NuGet Packages:
//  1) Newtonsoft.Json

using System;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Azure_Code_Snippets.Tutorial_Code
{
   class CloudServices_Merge
   {
      private enum FormatsEnum
      {
         Png = 1,
         Jpeg = 2,
         Tiff = 3,
         Pdf = 4,
         Pdfa = 5,
         PdfImage = 6,
         PdfImageOverText = 7,
         PdfaImageOverText = 8,
         Docx = 9,
         DocxFramed = 10,
         Rtf = 11,
         RtfFramed = 12,
         Txt = 13,
         TxtFramed = 14,
      }

      private string hostedServicesUrl = "https://azure.leadtools.com/api/";

      public async Task Merge()
      {
         var client = InitClient();


         string tiffUrl = "http://demo.leadtools.com/images/cloud_samples/ocr1-4.tif";
         string uploadUrl = string.Format("UploadFile?fileurl={0}&forMerge=true", tiffUrl);
         /*
        //If uploading a file as multi-part content:
        HttpContent byteContent = new ByteArrayContent(File.ReadAllBytes(@@"path/to/file"));
        byteContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
        {
           Name = "attachment",
           FileName = "file-name"
        };
        var formData = new MultipartFormDataContent();
        formData.Add(byteContent, "formFieldName");

        string uploadUrl = "UploadFile";
        var result = await client.PostAsync(uploadUrl, formData);
        formData.Dispose();
        */

         var result = await client.PostAsync(uploadUrl, null);
         if(result.StatusCode != HttpStatusCode.OK)
         {
            Console.WriteLine("Upload failed with the following response: " + result.StatusCode);
            return;
         }

         string firstFileId = await result.Content.ReadAsStringAsync();
         Console.WriteLine("First File ID returned by the services: " + firstFileId);
         if (!await CheckFileForVerification(firstFileId, client))
            return;

         string pdfUrl = "https://demo.leadtools.com/images/pdf/leadtools.pdf";
         uploadUrl = string.Format("UploadFile?fileurl={0}&forMerge=true", pdfUrl);

         result = await client.PostAsync(uploadUrl, null);
         if (result.StatusCode != HttpStatusCode.OK)
         {
            Console.WriteLine("Upload failed with the following response: " + result.StatusCode);
            return;
         }
         string secondFileid = await result.Content.ReadAsStringAsync();
         Console.WriteLine("Second File ID returned by the services: " + secondFileid);

         if (!await CheckFileForVerification(secondFileid, client))
            return;

         if(!await MergeFiles(client, firstFileId, secondFileid))
         {
            Console.WriteLine("Files failed to Merge");
            return;
         }

         await Query(firstFileId, client);

         Console.WriteLine("Done");
         Console.ReadKey();
      }

      private async Task<bool> MergeFiles(HttpClient client, string firstFileId, string secondFileId)
      {
         var mergeList = new List<MergeArgument>();
         mergeList.Add(new MergeFirstLast()
         {
            fileId = firstFileId,
            firstPage = 1,
            lastPage = -1
         });

         mergeList.Add(new MergePageArray()
         {
            fileId = secondFileId,
            pages = new int[]{ 5, 1, 2, 4, 2 }
         });

         //Final output format for the merged file
         var outputFormat = FormatsEnum.Pdf;
         var mergeUrl = string.Format("Conversion/Merge?format={0}", outputFormat);
         var response = await client.PostAsync(mergeUrl, new StringContent(JsonConvert.SerializeObject(mergeList), Encoding.UTF8, "application/json"));
         return response.StatusCode == HttpStatusCode.OK;
      }


      private async Task<bool> CheckFileForVerification(string id, HttpClient client)
      {
         string queryUrl = string.Format("Query?id={0}", id.ToString());
         var result = await client.PostAsync(queryUrl, null);
         var returnedContent = await result.Content.ReadAsStringAsync();
         var returnedData = JObject.Parse(returnedContent);
         var fileStatus = (int)returnedData.SelectToken("FileStatus");
         if (fileStatus == 123)
         {
            //The file is still being verified.  We will check every half a second to make sure that the file has been verified
            await Task.Delay(500);
            return await CheckFileForVerification(id, client);
         }
         if (fileStatus != 122)
         {
            Console.WriteLine(
quot;File ${id} failed verification with File Status: ${fileStatus}");
            return false;
         }

         return true;
      }

      private async Task Query(string id, HttpClient client)
      {
         string queryUrl = string.Format("Query?id={0}", id.ToString());
         var result = await client.PostAsync(queryUrl, null);
         var returnedContent = await result.Content.ReadAsStringAsync();
         var returnedData = JObject.Parse(returnedContent);
         int fileStatus = (int)returnedData.SelectToken("FileStatus");
         if (fileStatus == 100 || fileStatus == 123)
         {
            //The file is still being processed -- we will sleep the current thread for 5 seconds before trying again.
            await Task.Delay(5000);
            await Query(id, client);
            return;
         }

         Console.WriteLine("File has finished processing with return code: " + returnedData.SelectToken("FileStatus"));
         if ((int)returnedData.SelectToken("FileStatus") != 200)
            return;

         ParseJson(returnedData.SelectToken("RequestData").ToString());
      }

      private void ParseJson(string json)
      {
         JArray requestArray = JArray.Parse(json);
         foreach (var requestReturn in requestArray)
         {
            Console.WriteLine("Service Type: " + requestReturn.SelectToken("ServiceType"));
            Console.WriteLine("Returned Data:");
            var UrlArray = JArray.Parse(requestReturn.SelectToken("urls").ToString());
            foreach (var obj in UrlArray)
            {
               Console.WriteLine(obj.ToString());
            }
         }
      }

      private HttpClient InitClient()
      {
         string AppId = "Replace with Application ID";
         string Password = "Replace with Application Password";

         HttpClient client = new HttpClient();
         client.BaseAddress = new Uri(hostedServicesUrl);
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

         string authData = string.Format("{0}:{1}", AppId, Password);
         string authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);

         return client;
      }

      private class MergeArgument
      {
         public string fileId { get; set; }
      }

      private class MergeFirstLast: MergeArgument
      {
         public int firstPage { get; set; }
         public int lastPage { get; set; }
      }

      private class MergePageArray : MergeArgument
      {
         public int[] pages { get; set; }
      }
   }
}



Note: This example uses the following additional third-party libraries: Newtonsoft.Json.