How to get a Quote with the SevenCorners API

The code seen below is the C# code showing what steps are needed to get the information from the Seven Corners system for a quote. Additional information would need to be gathered from a web page to update all the data shown as strings in the quote body. This should be done using JSON or other object types and updating those objects. It was done in plan text in the example below so that the code resembles that of what you see in the Interactive API.

using System;

using System.Collections.Generic;

using System.Dynamic;

using System.IO;

using System.Linq;

using System.Net;

using System.Text;

using System.Threading.Tasks;

using Newtonsoft.Json;

using RestSharp;

namespace QuickQuote

{

    class Program

    {

        static void Main(string[] args)

        {

            //Welcome to the Development Code overview for process calls while doing a quote - A number of the commented

            //portions of the code can be used for testing. This package also uses RestSharp, however HTTP requests can

            //also be used. Rest was implemented in this case for easy understanding and readability. The use of plain

            //text that is seen below was also for ease of understanding when used with Interactive API on the developer site.

            //   QUICK QUOTE BASIC STEPS

            //   1 / token - https://api.sevencorners.com/token

            //   2 / api / v1 / Products / DefaultPolicyFormDefinition - https://api.sevencorners.com/api/v1/products/policyformdefinition/30

            //   3 / api / v1 / lookup / eligiblecountriesforproductgroup - https://api.sevencorners.com/api/v1/lookup/eligiblecountriesforproductgroup/30

            //   4 / api / v1 / lookup / eligiblestatesforproductgroup - https://api.sevencorners.com/api/v1/lookup/eligiblestatesforproductgroup/30/1

            //   5 / api / v1 / lookup / allcountries - https://api.sevencorners.com/api/v1/lookup/allcountries

            // The above data as well as additional data from purchaser allows for a quote to be pulled.

            //   6 / api / v1 / lookup / quote - https://api.sevencorners.com/api/v1/quote

            //STEP 1

            //Setting Agent Variables

            string grant_type = "client_credentials";

            string APIKey = "BC7D5CE1-4929-422D-87EE-CC9968F72C03"; //YOU MUST ENTER A KEY FOR THIS TO WORK

            string AuthorizationKey = "";

            //Creating Token Request

            string TokenURL = "https://api.sevencorners.com/token";

            var client = new RestClient(TokenURL);

            client.CookieContainer = new CookieContainer();

            var request = new RestRequest(Method.POST);

            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

            request.AddHeader("Accept", "application/json");

            request.AddParameter("application/x-www-form-urlencoded", "grant_type=" + grant_type + "&client_id=" + APIKey, ParameterType.RequestBody);

            //Handle Response

            IRestResponse response = client.Execute(request);

            //Evaluate Response Code (this is not done in this example)

            string rcode = response.StatusCode.ToString();

            //Set AuthorizationKey - EXAMPLE OF WHERE TO USE JSON DESERIALIZATION

            string[] values = response.Content.Split(',');

            string[] subvalues = values[0].Split(':');

            AuthorizationKey = subvalues[1].TrimStart('"').TrimEnd('"');

            //AuthorizationHeader used for subsequent calls to API

            //request.AddHeader("Authorization", "Bearer "+AuthorizationKey);

            //Prints out the Key to validate you have the long string representation (TESTING)

            //Console.WriteLine(AuthorizationKey);

            //STEP 2

            //Gathering Default Policy definition by Product Group ID - 30 = Liason Continent

            string RequestURL2 = "https://api.sevencorners.com/api/v1.1/products/defaultpolicyformdefinition/30"; //This string could be mutated for different policies

            var client2 = new RestClient(RequestURL2);

            var request2 = new RestRequest(Method.GET);

            request2.AddHeader("Accept", "application/json");

            request2.AddHeader("Authorization", "Bearer " + AuthorizationKey);

            //Handle Response

            var queryResult2 = client2.Execute(request2);

            //Show response values

            //Console.WriteLine();

            //Console.WriteLine(queryResult2.Content); //parse data into fields and use as needed

            //Console.ReadLine();

            //STEP 3

            //Creating Token Request

            string RequestURL3 = "https://api.sevencorners.com/api/v1/lookup/eligiblecountriesforproductgroup/30"; //This string could be mutated for different product groups

            var client3 = new RestClient(RequestURL3);

            var request3 = new RestRequest(Method.GET);

            request3.AddHeader("Accept", "application/json");

            request3.AddHeader("Authorization", "Bearer " + AuthorizationKey);

            //Handle Response

            var queryResult3 = client3.Execute(request3);

            //Show response values

            //Console.WriteLine();

            //Console.WriteLine(queryResult3.Content); //parse data into fields and use as needed

            //Console.ReadLine();

            //STEP 4

            //Creating Token Request

            string RequestURL4 = "https://api.sevencorners.com/api/v1.1/lookup/eligiblestatesforproductgroup/30/USA"; //This string could be mutated for different policies

            var client4 = new RestClient(RequestURL4);

            var request4 = new RestRequest(Method.GET);

            request4.AddHeader("Accept", "application/json");

            request4.AddHeader("Authorization", "Bearer " + AuthorizationKey);

            //Handle Response

            var queryResult4 = client4.Execute(request4);

            //Show response values

            //Console.WriteLine();

            //Console.WriteLine(queryResult4.Content); //parse data into fields and use as needed

            //Console.ReadLine();

            //STEP 5

            //Creating Token Request

            string RequestURL5 = "https://api.sevencorners.com/api/v1/lookup/allcountries"; //This string could be mutated for different policies

            var client5 = new RestClient(RequestURL5);

            var request5 = new RestRequest(Method.GET);

            request5.AddHeader("Accept", "application/json");

            request5.AddHeader("Authorization", "Bearer " + AuthorizationKey);

            //Handle Response

            var queryResult5 = client5.Execute(request5);

            //Show response values

            //Console.WriteLine();

            //Console.WriteLine(queryResult5.Content); //parse data into fields and use as needed

            //Console.ReadLine();

            //STEP 6

            //Creating the Quote request body - THIS SHOULD BE DONE WITH DATA PULLED FROM WEBPAGE AND WEBREQUESTS - BELOW EXAPMLE DATA - USE JSON OBJECTS SERIALIZATION

            // Developers note: You can use the testing API to validate the data you provide to objects without having to do live development. Replacing values in the request

            // ANY object used below with a sub-menu should be represented in an object class. The method shown below is to go with the API.

            var body =

                "{\"quoteIdentifier\":\"string\"," +

                "\"groupQuoteIdentifier\":\"string\"," +

                "\"quoteRequestCount\": 0," +

                "\"policyQuoteRequests\": [{" +

                "\"policyId\": 0," +

                    "\"productGroupId\":0," +

                    "\"unitIdentifier\":0," +

                    "\"purchaseDate\":\"2017-03-02T14:36:51.723Z\"," +

                    "\"effectiveDate\":\"2017-03-02T14:36:51.723Z\"," +

                    "\"expirationDate\":\"2017-03-02T14:36:51.723Z\"," +

                    "\"fields\": [" +

                        "{\"code\":\"string\"," +

                        "\"value\":\"string\"}]," +

                    "\"personFields\": [{" +

                        "\"personIdentifier\":\"string\"," +

                        "\"fields\": [" +

                            "{\"code\":\"string\"," +

                            "\"value\":\"string\"}]}]}]," +

                "\"persons\": [{" +

                    "\"clientPersonIdentifier\":\"string\"," +

                    "\"prefix\":\"string\"," +

                    "\"suffix\":\"string\"," +

                    "\"gender\":\"string\"," +

                    "\"SocialSecurityNumber\":\"string\"," +

                    "\"height\":\"string\"," +

                    "\"heightUnitOfMeasure\": 0," +

                    "\"weight\":\"string\"," +

                    "\"weightUnitOfMeasure\": 0," +

                    "\"relationship\":\"Primary\"," +

                    "\"alternateId\":\"string\"," +

                    "\"familyUnitId\": 0," +

                    "\"phones\": [{" +

                        "\"phoneNumber\":\"string\"," +

                        "\"phoneType\":\"Work\"}]," +

                    "\"emails\": [{" +

                        "\"emailAddress\":\"string\"," +

                        "\"isWorkEmail\":\"true\"," +

                        "\"isDefault\":\"true\"}]," +

                    "\"firstName\":\"string\"," +

                    "\"middleName\":\"string\"," +

                    "\"lastName\":\"string\"," +

                    "\"dateOfBirth\":\"1997-03-02T14:36:51.723Z\"}]," +

                "\"primaryMemberAddresses\":[{" +

                "\"type\":\"Billing\"," +

                    "\"addressLine1\":\"string\"," +

                    "\"addressLine2\":\"string\"," +

                    "\"addressLine3\":\"string\"," +

                    "\"addressLine4\":\"string\"," +

                    "\"addressLine5\":\"string\"," +

                    "\"city\":\"string\"," +

                    "\"countryCode\":\"string\"," +

                    "\"state\":\"string\"," +

                    "\"postalCode\":\"true\"}]}";

            //NOTE: This format is the same that is shown by the Interactive Testing API

            //Creating Quote Request

            string QuoteURL = "https://api.sevencorners.com/api/v1/quote"; //This string could be mutated for different policies

            var client6 = new RestClient(QuoteURL);

            var request6 = new RestRequest(Method.POST);

            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

            request6.AddHeader("Accept", "application/json");

            request6.AddHeader("Authorization", "Bearer " + AuthorizationKey);

            request6.AddParameter("application/json", body, ParameterType.RequestBody);

            //Handle Response

            var queryResult6 = client6.Execute(request6);

            //Show response values

            Console.WriteLine();

            Console.WriteLine(queryResult6.Content); //parse data into fields and use as needed

            Console.ReadLine();

        }

    }

}

Documents

Privacy Information
Terms of Use
Security Statement

Connect with Seven Corners

About Us
Newsroom
Careers

   

Contact Us