C# example to help you get started. The example shows how to use the plugin to send an API request and get a response from the server.

Please refer to the previous sections coded in PHP to find more details about the APIs parameters and responses, this is just a code sample.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Net.Http;
using Newtonsoft.Json;

namespace License_Manager_API
{
    internal static class Program
    {
        private static readonly HttpClient Client = new HttpClient();

        /**
         * The Post Url is your domain name, if your WordPress installation is in a sub folder the Post Url should include the sub folder.
         * Example:
         *     https://domain.ltd/
         *     https://domain.ltd/sub-folder/
         */
        private const string PostUrl = "https://demo.firassaidi.com/wc-license-manager/";

        public static void Main()
        {
            var result = Program.VerifyLicenseKey().Result;
            Console.WriteLine("Verify:                  " + result);


            // Parse JSON response
            dynamic parsedJson = JsonConvert.DeserializeObject(result);

            // Extracting the values form the parsedJson.
            string r = parsedJson.result;
            string code = parsedJson.code;
            string message = parsedJson.message;

            Console.WriteLine(r);
            Console.WriteLine(code);
            Console.WriteLine(message + "\n");


            result = Program.KeyStatus().Result;
            Console.WriteLine("License Status:          " + result + "\n");

            result = Program.ActivateLicenseKey().Result;
            Console.WriteLine("Activate:                " + result + "\n");

            result = Program.KeyStatus().Result;
            Console.WriteLine("License Status:          " + result + "\n");

            result = Program.DeactivateLicenseKey().Result;
            Console.WriteLine("Deactivate:              " + result + "\n");

            result = Program.KeyStatus().Result;
            Console.WriteLine("License Status:          " + result + "\n");

            result = Program.DetailsLicenseKey().Result;
            Console.WriteLine("License Key Details:     " + result + "\n");

            result = Program.ExtraData().Result;
            Console.WriteLine("Extra Product Data:      " + result + "\n");

            result = Program.KeyStatus().Result;
            Console.WriteLine("License Status:          " + result + "\n");

            Console.ReadKey();
        }

        private static async Task<string> ActivateLicenseKey()
        {
            var values = new Dictionary<string, string>
            {
                {"fslm_v2_api_request", "activate"}, // The action 
                {"fslm_api_key", "0A9Q5OXT13in3LGjM9F3"}, // The API key
                {"license_key", "PDN3NDD5RHX"}, // The License Key
                {"device_id", "domain.ltd"} // The License Key
            };

            var content = new FormUrlEncodedContent(values);
            var response = await Client.PostAsync(PostUrl, content);
            var responseString = await response.Content.ReadAsStringAsync();

            // The variable responseString contains the query result
            return responseString;
        }

        private static async Task<string> DeactivateLicenseKey()
        {
            var values = new Dictionary<string, string>
            {
                {"fslm_v2_api_request", "deactivate"}, // The action
                {"fslm_api_key", "0A9Q5OXT13in3LGjM9F3"}, // The API key
                {"license_key", "PDN3NDD5RHX"}, // The License Key
                {"device_id", "domain.ltd"} // The License Key
            };

            var content = new FormUrlEncodedContent(values);
            var response = await Client.PostAsync(PostUrl, content);
            var responseString = await response.Content.ReadAsStringAsync();

            // The variable responseString contains the query result
            return responseString;
        }

        private static async Task<string> VerifyLicenseKey()
        {
            var values = new Dictionary<string, string>
            {
                {"fslm_v2_api_request", "verify"}, // The action
                {"fslm_api_key", "0A9Q5OXT13in3LGjM9F3"}, // The API key
                {"license_key", "PDN3NDD5RHX"} // The License Key
            };

            var content = new FormUrlEncodedContent(values);
            var response = await Client.PostAsync(PostUrl, content);
            var responseString = await response.Content.ReadAsStringAsync();

            // The variable responseString contains the query result
            return responseString;
        }

        private static async Task<string> DetailsLicenseKey()
        {
            var values = new Dictionary<string, string>
            {
                {"fslm_v2_api_request", "details"}, // The action
                {"fslm_api_key", "0A9Q5OXT13in3LGjM9F3"}, // The API key
                {"license_key", "PDN3NDD5RHX"} // The License Key
            };

            var content = new FormUrlEncodedContent(values);
            var response = await Client.PostAsync(PostUrl, content);
            var responseString = await response.Content.ReadAsStringAsync();

            // The variable responseString contains the query result
            return responseString;
        }

        private static async Task<string> ExtraData()
        {
            var values = new Dictionary<string, string>
            {
                {"fslm_v2_api_request", "ExtraData"}, // The action
                {"fslm_api_key", "0A9Q5OXT13in3LGjM9F3"}, // The API key
                {"product_id", "98"} // product ID
            };

            var content = new FormUrlEncodedContent(values);
            var response = await Client.PostAsync(PostUrl, content);
            var responseString = await response.Content.ReadAsStringAsync();

            // The variable responseString contains the query result
            return responseString;
        }

        private static async Task<string> KeyStatus()
        {
            var values = new Dictionary<string, string>
            {
                {"fslm_v2_api_request", "license_status"}, // The action
                {"fslm_api_key", "0A9Q5OXT13in3LGjM9F3"}, // The API key
                {"license_key", "PDN3NDD5RHX"} // The License Key
            };

            var content = new FormUrlEncodedContent(values);
            var response = await Client.PostAsync(PostUrl, content);
            var responseString = await response.Content.ReadAsStringAsync();

            // The variable responseString contains the query result
            return responseString;
        }
    }
}
Was this article helpful to you? Yes No