Using Episerver CMS as a makeshift API – Part 2, Stopping at the beginning

In part 1, I briefly explained how I came to work on writing an API for an Episerver CMS by exploiting the front-end framework on the web interface. As a developer, with a finite life-span, I jumped straight to the part that I needed for the job. I had intended to go back to the beginning and map all the functionality. Unfortunately I haven’t had very much time to spend on this. Together with an amount of uncertainty of my future with Episerver, I’m shelving this. My day job is with Episerver and it’s always possible that this API will get reignited by some requirements later.

If you’re curious how I’m mapping the functionality, I’m running the demo “Alloy Site” and using Telerik Fiddler to log the HTTP traffic. Then I’m going through the log and pulling out the request and responses. I’m generating the C# classes from the JSON response using Xamasoft’s JSON C# Class Generator. The JSON Class Generator is a great start but requires a significant amount of changes.

I hope this has been helpful to someone.

Here is what I have, starting at the beginning.

 

1) Preparations

This is a quick recap on the setup and logins.


using RyzStudio.Web.Episerver;

protected EpiserverCMS episerverCMS = new EpiserverCMS {
  BaseURL = @"http://localhost:5156",
  BaseURLCMS = @"http://localhost:5156"
};

episerverCMS.Login("Admin", "Password1234");

 

2) Get current username

Get the currently logged-in username.


string username = episerverCMS.GetProfile_Username();

Console.WriteLine("Hello, " + username);

 

3) Get sites

Get the sites running from this instance.


List<SiteStructure> siteStructureList = episerverCMS.GetSiteStructure();
if (siteStructureList != null)
{
  foreach (SiteStructure row in siteStructureList)
  {
    Console.WriteLine(row.Name + " (" + row.URL + ")");
  }
}

 

4) Get visitor groups


List<IDName> visitorGroupList = episerverCMS.GetVisitorGroup();
if (siteStructureList != null)
{
  foreach (IDName row in visitorGroupList)
  {
    Console.WriteLine(row.Name + " (" + row.ID + ")");
  }
}

 

5) Get channels


List<Channel> channelList = episerverCMS.GetChannel_GetAllRegistered();
if (siteStructureList != null)
{
  foreach (Channel row in channelList)
  {
    Console.WriteLine(row.Name + " (" + (row.IsActive ? "Active" : "Inactive") + ")");
  }
}

 

6) Check license


LicenseInformation licenseInformation = episerverCMS.GetLicenseInformation();
if (licenseInformation != null)
{
  Console.WriteLine(licenseInformation.IsValid.ToString());
}

 

7) Get languages

Get supported/enabled cultures.


List<Language> languagesList = episerverCMS.GetLanguage();
if (siteStructureList != null)
{
  foreach (Language row in languagesList)
  {
    Console.WriteLine(row.CultureName + " (" + row.LanguageID + ")");
  }
}

 

8) Show site structure (with culture)


if (siteStructureList != null)
{
  foreach (SiteStructure row in siteStructureList)
  {
    List<SiteStructure> siteStructureList2 = episerverCMS.GetSiteStructure_SiteURL(row.URL);
    if (siteStructureList2 != null)
    {
      Console.WriteLine(row.Name + " (" + row.URL + ")");

      foreach (SiteStructure row2 in siteStructureList2)
      {
        Console.WriteLine(row2.Name + " (" + row2.URL + ")");
      }
    }
  }
}

 

I hope someone finds this interesting or useful.

Code Repository

Social Media

 Share Tweet

Categories

Programming

Tags

.NET C# Episerver

Post Information

Posted on Sun 4th Mar 2018

Modified on Sat 5th Aug 2023