TigerMan
03/15/2024, 2:49 PMAnders Bjerner
03/15/2024, 3:51 PM/umbraco/Limbo/Migrations/GetContentAtRoot?maxLevel=999
The endpoint does however only expose property data for the first level of nodes. But children/descendants can be requested specifically - eg. /umbraco/Limbo/Migrations/GetContentById?id=1234
I've been using this for a handful og migrations along with https://github.com/limbo-works/Limbo.Umbraco.MigrationsClient which essentially is a wrapper for the API.TigerMan
03/15/2024, 8:48 PMTigerMan
03/28/2024, 1:54 PMAnders Bjerner
03/28/2024, 2:08 PM/umbraco/Limbo/Migrations/GetContentAtRoot?maxLevel=999
would give you the entire site structure. But the returned objects will only contain basic information about each page - not the properties of each page.
If you request more information about a specific page - eg. /umbraco/Limbo/Migrations/GetContentById?id=1234
you will get a larger object, including the properties of the page.
2)
I think this depends a lot on your setup. Personally I've used my Limbo.Umbraco.Migrations package for this: https://github.com/limbo-works/Limbo.Umbraco.Migrations
The package contains classes representing models for some of Umbraco's property editors - eg. the block list or a media picker: https://github.com/limbo-works/Limbo.Umbraco.Migrations/tree/v1/main/src/Limbo.Umbraco.Migrations/Models
When serialized to JSON (using JSON.net), the JSON values should match what Umbraco is saving when you make changes via the backoffice.
Unfortunately the package is primarily something I've used internally, so there isn't any documentation. Ideally there should be, but my time has been taken up by other stuff.TigerMan
03/28/2024, 5:52 PMAnders Bjerner
03/28/2024, 8:06 PMTigerMan
03/28/2024, 8:14 PMAnders Bjerner
03/28/2024, 8:15 PMTigerMan
03/28/2024, 8:19 PMAnders Bjerner
03/28/2024, 8:21 PMTigerMan
03/28/2024, 8:50 PMAnders Bjerner
03/28/2024, 9:15 PMAnders Bjerner
03/28/2024, 9:15 PMTigerMan
03/28/2024, 9:38 PMAnders Bjerner
03/28/2024, 9:58 PMAnders Bjerner
03/28/2024, 10:21 PMcshtml
@using Limbo.Umbraco.MigrationsClient
@using Limbo.Umbraco.MigrationsClient.Models.Content
@using Limbo.Umbraco.MigrationsClient.Models.Properties
@using Newtonsoft.Json.Linq
@using Skybrud.Umbraco.GridData.Factories
@using Skybrud.Umbraco.GridData.Models
@inherits UmbracoViewPage
@inject IMigrationsClient MigrationsClient
@inject IGridFactory GridFactory
@{
LegacyContent content = MigrationsClient.GetContentById(1077);
<pre>ID: @content.Id</pre>
<pre>Name: @content.Name</pre>
<h3>Properties:</h3>
foreach (ILegacyProperty property in content.Properties) {
<h3>@property.Alias (@property.EditorAlias)</h3>
<pre>@property.Value</pre>
switch (property.EditorAlias) {
case "Umbraco.Grid":
object? newValue = ConvertGridValue(property.Value);
break;
}
}
}
@functions {
public object? ConvertGridValue(JToken value) {
return value.Type switch {
JTokenType.Null => null,
JTokenType.Object => ConvertGridValue(GridFactory.CreateGridModel(null, null, (JObject)value, false)),
_ => throw new Exception($"Unsupported token type: {value.Type}...")
};
}
public object? ConvertGridValue(GridDataModel value) {
throw new Exception("YAY");
}
}
Anders Bjerner
03/28/2024, 10:23 PMTigerMan
03/28/2024, 10:24 PMAnders Bjerner
03/28/2024, 10:26 PMTigerMan
03/28/2024, 10:35 PMAnders Bjerner
03/28/2024, 10:42 PMTigerMan
03/28/2024, 10:46 PMAnders Bjerner
03/28/2024, 10:49 PMcshtml
@using Limbo.Umbraco.MigrationsClient
@using Limbo.Umbraco.MigrationsClient.Models.Content
@using Limbo.Umbraco.MigrationsClient.Models.Properties
@using Newtonsoft.Json
@using Newtonsoft.Json.Linq
@using Umbraco.Cms.Core.Models
@using Umbraco.Cms.Core.Services
@inherits UmbracoViewPage
@inject IContentService ContentService
@inject IMigrationsClient MigrationsClient
@{
LegacyContent legacy = MigrationsClient.GetContentById(1077);
<pre>ID: @legacy.Id</pre>
<pre>Key: @legacy.Key</pre>
<pre>Name: @legacy.Name</pre>
<h3>Properties:</h3>
IContent? content = ContentService.GetById(legacy.Key);
if (content is null) {
var parent = legacy.Path.SkipLast().LastOrDefault();
content = ContentService.Create(legacy.Name, parent?.Id ?? -1, legacy.ContentTypeAlias);
}
foreach (ILegacyProperty property in legacy.Properties) {
<h3>@property.Alias (@property.EditorAlias)</h3>
<pre>@property.Value</pre>
switch (property.Value.Type) {
case JTokenType.Null:
continue;
case JTokenType.Array:
case JTokenType.Object:
content.SetValue(property.Alias, property.Value.ToString(Formatting.None));
break;
case JTokenType.String:
content.SetValue(property.Alias, property.Value.Value<string>());
break;
case JTokenType.Integer:
content.SetValue(property.Alias, property.Value.Value<int>());
break;
default:
throw new Exception($"Unsupported token type: {property.Value.Type}...");
}
}
ContentService.SaveAndPublish(content);
}
Anders Bjerner
03/28/2024, 10:52 PMcshtml
@using Limbo.Umbraco.MigrationsClient
@using Limbo.Umbraco.MigrationsClient.Models.Content
@using Newtonsoft.Json.Linq
@inherits UmbracoViewPage
@inject IMigrationsClient MigrationsClient
@{
LegacyContent legacy = MigrationsClient.GetContentById(1077);
JObject json = legacy.JObject!;
string jsonString = json.ToString();
<h3>API response body as JObject</h3>
<pre>@json</pre>
<h3>API response body as string</h3>
<pre>@jsonString</pre>
}
I'm still not sure why you wish to expose this in an API on the U13 site though. I think this may take you down a wrong pathTigerMan
03/28/2024, 11:01 PM