C# example for creating and associating a brand with a library

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

namespace CreateLibraryBrandingInSB
{
    class Program
    {
        //Authentication Info.
        public static string BaseURI = "https://app.sharebase.com/sharebaseapi/";
        public static string Token = "";
        public static string ShareBaseEmailId = "user";
        public static string ShareBasePassword = "password";
        public static string Origin = "http://{your-computer-name-here}";

        //Branding Information
        public const string EmailLogoFilePath = "M:\\{path-to-your-email-logo}.png";
        public const string LoginLogoFilePath = "M:\\{path-to-your-login-logo}.jpg";
        public const string WebLogoFilePath = "M:\\{path-to-your-web-logo}.png";
        public const string PrimaryColor = "#AABBCC"; //Should be replaced with the hexadecimal color for your primary color
        public const string SecondaryColor = "#DDEEFF"; //Should be replaced with the hexadecimal color for your secondary color
        public const string ApplicationName = "Your-Application";
        public const string Description = "A Description of the Branding";
        public const string Title = "The Title of Your Branding";
        public const long LibraryId = 1; //The id of the library being branded should be used in place of 1

         static async Task Main(string[] args)
        {
            //Authenticate for Sharebase User.
            await AuthenticateAsync(ShareBaseEmailId, ShareBasePassword);

            await CreateLibraryBranding();

            Console.WriteLine("It worked");
        }

        public static async Task AuthenticateAsync(string email, string password)
        {
            HttpClient httpClient = new HttpClient();
            Token = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(email + ":" + password));
            httpClient.DefaultRequestHeaders.Add("Authorization", Token);

            HttpResponseMessage tokenResponse = await httpClient.GetAsync(BaseURI + "authenticate");

            string responseAsString = await tokenResponse.Content.ReadAsStringAsync();
            dynamic jsonResponse = JsonConvert.DeserializeObject(responseAsString);
            Token = GetValueFromJsonObject(jsonResponse, "Token");
            Token = "PHOENIX-TOKEN " + Token;
        }

        public static async Task CreateLibraryBranding()
        {
            HttpClient httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Add("Authorization", Token);

            string base64EmailLogo = ConvertFileToBase64(EmailLogoFilePath);
            string base64LoginLogo = ConvertFileToBase64(LoginLogoFilePath);
            string base64WebLogo = ConvertFileToBase64(WebLogoFilePath);

            DynamicBrandingRequest dynamicBrandingRequest = new DynamicBrandingRequest
            {
                ApplicationName = ApplicationName,
                Base64EmailLogo = base64EmailLogo,
                Base64LoginLogo = base64LoginLogo,
                Base64WebLogo = base64WebLogo,
                Description = Description,
                PrimaryColor = PrimaryColor,
                SecondaryColor = SecondaryColor,
                Title = Title
            };

            HttpContent dynamicBrandingContent = new StringContent(JsonConvert.SerializeObject(dynamicBrandingRequest), Encoding.UTF8, MediaTypeNames.Application.Json);
            HttpResponseMessage dynamicBrandingResponse = await httpClient.PostAsync(BaseURI + "api/dynamic-brandings", dynamicBrandingContent);
            string responseAsString = await dynamicBrandingResponse.Content.ReadAsStringAsync();
            dynamic jsonResponse = JsonConvert.DeserializeObject(responseAsString);
            long dynamicBrandingId = Convert.ToInt64(GetValueFromJsonObject(jsonResponse, "DynamicBrandingId"));

            LibraryBrandingRequest libraryBrandingRequest = new LibraryBrandingRequest
            {
                DynamicBrandingId = dynamicBrandingId
            };

            HttpContent libraryBrandingContent = new StringContent(JsonConvert.SerializeObject(libraryBrandingRequest), Encoding.UTF8, MediaTypeNames.Application.Json);
            await httpClient.PostAsync(BaseURI + $"api/libraries/{LibraryId}/branding", libraryBrandingContent);
        }


        public static string ConvertFileToBase64(string filePath)
        {
            return Convert.ToBase64String(File.ReadAllBytes(filePath));
        }
        public static string GetValueFromJsonObject(dynamic json, string propertyName)
        {
            string val = string.Empty;
            foreach (var ma in json)
            {
                if (ma != null && ma.Name.ToString() == propertyName)
                {
                    val = ma.Value.ToString();
                    break;
                }
            }
            return val;
        }
    }

    public class DynamicBrandingRequest
    {
        public string ApplicationName { get; set; }
        public string Base64EmailLogo { get; set; }
        public string Base64LoginLogo { get; set; }
        public string Base64WebLogo { get; set; }
        public string Description { get; set; }
        public string PrimaryColor { get; set; }
        public string SecondaryColor { get; set; }
        public string Title { get; set; }
    }

    public class LibraryBrandingRequest
    {
        public long DynamicBrandingId { get; set; }
    }
}