CDBalancer takes 2 processed Closing Disclosure documents and balances them.
Asynchronous CDBalancer
The entire flow is asynchronous, meaning that when you start the cdbalancer we will respond with a request_id which you can use to track of the status of the cdbalancer request.
While users of Areal Dashboard can easily see the live status of their cdbalancer requests.
So if you are planning to integrate our API, you can use our WebSocket API or manually poll the status of the cdbalancer request.
importrequestsBASE_URL="http://dev-api.v2.areal.ai/api/v2"# 0. Login - details in Authentication section# 1. Process Documents that you are interested in balancing# -- For this, please refer to the Processing section# 2. Call CDBalancer API using existing processed documentscdbalancer_response=client.post(url=f"{BASE_URL}/cdbalancer/",json={"document_id_1":"doc1_id","document_id_2":"doc2_id"},headers={"Content-Type":"application/json"},)request_id=cdbalancer_response.json()["request_id"]
usingSystem;usingSystem.Net.Http;usingSystem.Threading.Tasks;usingSystem.Text;usingSystem.Text.Json;usingSystem.Net;varbaseUrl="http://dev-api.v2.areal.ai/api/v2";// 0. Login - details in Authentication section// See code_samples/auth/c#/login.cs for authenticationvarhandler=newHttpClientHandler{UseCookies=true,CookieContainer=newCookieContainer()};varclient=newHttpClient(handler);// 1. Process Documents that you are interested in balancing// -- For this, please refer to the Processing section// See code_samples/processing/c#/start_processing.cs// 2. Call CDBalancer API using existing processed documentsvarcdbalancerRequest=new{document_id_1="doc1_id",document_id_2="doc2_id"};varcdbalancerContent=newStringContent(JsonSerializer.Serialize(cdbalancerRequest),Encoding.UTF8,"application/json");varcdbalancerResponse=awaitclient.PostAsync($"{baseUrl}/cdbalancer/",cdbalancerContent);cdbalancerResponse.EnsureSuccessStatusCode();varcdbalancerResponseJson=awaitcdbalancerResponse.Content.ReadAsStringAsync();varcdbalancerData=JsonSerializer.Deserialize<JsonElement>(cdbalancerResponseJson);varrequestId=cdbalancerData.GetProperty("request_id").GetString();
importjava.net.HttpURLConnection;importjava.net.URL;importjava.io.OutputStream;importjava.io.BufferedReader;importjava.io.InputStreamReader;importjava.net.CookieManager;importjava.net.CookieHandler;importjava.nio.charset.StandardCharsets;importorg.json.JSONObject;publicclassCDBalancerExample{publicstaticvoidmain(String[]args)throwsException{StringbaseUrl="http://dev-api.v2.areal.ai/api/v2";// 0. Login - details in Authentication section// See code_samples/auth/java/login.java for authenticationCookieManagercookieManager=newCookieManager();CookieHandler.setDefault(cookieManager);// 1. Process Documents that you are interested in balancing// -- For this, please refer to the Processing section// See code_samples/processing/java/start_processing.java// 2. Call CDBalancer API using existing processed documentsJSONObjectcdbalancerRequest=newJSONObject();cdbalancerRequest.put("document_id_1","doc1_id");cdbalancerRequest.put("document_id_2","doc2_id");JSONObjectcdbalancerResponse=makeAuthenticatedRequest(baseUrl+"/cdbalancer/","POST",cdbalancerRequest.toString());StringrequestId=cdbalancerResponse.getString("request_id");}privatestaticJSONObjectmakeAuthenticatedRequest(StringurlString,Stringmethod,Stringbody)throwsException{URLurl=newURL(urlString);HttpURLConnectionconnection=(HttpURLConnection)url.openConnection();connection.setRequestMethod(method);connection.setRequestProperty("Content-Type","application/json");connection.setDoOutput(true);// Cookies are automatically handled by CookieManagerif(body!=null){try(OutputStreamos=connection.getOutputStream()){byte[]input=body.getBytes(StandardCharsets.UTF_8);os.write(input,0,input.length);}}intresponseCode=connection.getResponseCode();if(responseCode==HttpURLConnection.HTTP_OK){try(BufferedReaderbr=newBufferedReader(newInputStreamReader(connection.getInputStream(),StandardCharsets.UTF_8))){StringBuilderresponse=newStringBuilder();StringresponseLine;while((responseLine=br.readLine())!=null){response.append(responseLine.trim());}returnnewJSONObject(response.toString());}}connection.disconnect();returnnull;}}