Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Load data from the DNN Evoq Liquid Content API using the DNN Razor Host module. Razor gives you a bit more control and flexibility than the built-in visualizers.
@using System
@using System.Net
@using System.Text
@using Newtonsoft.Json
@using Newtonsoft.Json.Linq
@{
// The API URL and your API Key
string url = "https://dnnapi.com/content/api/ContentItems?contentTypeId=7f0d48be-a6bf-4f3c-9fdf-ba895727e818";
string apikey = "**** INSERT YOUR API KEY HERE ****";
// Declare the result variables
string lcjson = String.Empty;
string err = String.Empty;
JObject lcObject = null;
JArray items = null;
IEnumerable<Newtonsoft.Json.Linq.JToken> jobs = null;
// First, we'll set up the http request
var myWebRequest = WebRequest.Create(url);
var myHttpWebRequest = (HttpWebRequest)myWebRequest;
myHttpWebRequest.Method = "GET";
myHttpWebRequest.PreAuthenticate = true;
myHttpWebRequest.Headers.Add("Authorization", "Bearer " + apikey);
myHttpWebRequest.Accept = "application/json";
// Get the JSON response from the API
try
{
var myWebResponse = myHttpWebRequest.GetResponse();
var responseStream = myWebResponse.GetResponseStream();
if (responseStream != null) {
var myStreamReader = new StreamReader(responseStream, Encoding.Default);
lcjson = myStreamReader.ReadToEnd();
}
responseStream.Close();
myWebResponse.Close();
}
catch(Exception ex)
{
err = ex.ToString();
}
// Parse JSON into an object
if (lcjson != String.Empty)
{
lcObject = JObject.Parse(lcjson);
items = (JArray)lcObject["documents"];
jobs =
from j in items
select j["details"];
}
}
<div class="container">
<div class="row">
<!-- If we have an error, tell the user what went wrong -->
@if (err != String.Empty)
{
<div class="col mb-4 bump bump-primary">@err</div>
}
<!-- List of jobs -->
<div class="col-12 mb-4">
<h2>@jobs.Count() vacancies in the system</h2>
</div>
@foreach (var x in jobs)
{
<div class="col mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">
@x["jobTitle"]
<em>at</em>
@x["firmName"]
</h5>
<p class="card-text">
@x["jobIntroduction"]
</p>
</div>
</div>
</div>
}
<!-- Here's the JSON data from the Liquid Content API -->
<div class="col mb-4">
<div class="bump bump-primary">
@ObjectInfo.Print(items)
</div>
</div>
<!-- Don't forget we have full access to the DNN API here -->
<div class="col mb-4">
<div class="bump bump-primary">
@ObjectInfo.Print(Dnn)
</div>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.