Skip to content

Instantly share code, notes, and snippets.

@SebastianStehle
Created January 24, 2024 15:20
Show Gist options
  • Save SebastianStehle/f0ed44b2c9933d3bd6830df8e164e1e3 to your computer and use it in GitHub Desktop.
Save SebastianStehle/f0ed44b2c9933d3bd6830df8e164e1e3 to your computer and use it in GitHub Desktop.
using Squidex.ClientLibrary;
using System.Text.Json;
var idsFile = File.ReadAllText("failed-ids.json");
var idsList = JsonSerializer.Deserialize<List<string>>(idsFile)!;
var appName = "ids-test";
var client = new SquidexClient(new SquidexOptions
{
AppName = appName,
ClientId = "root",
ClientSecret = "xeLd6jFxqbXJrfmNLlO2j1apagGGGSyZJhFnIuHp4I0=",
Url = "https://localhost:5001",
IgnoreSelfSignedCertificates = true,
});
try
{
await client.Apps.PostAppAsync(new CreateAppDto
{
Name = appName
});
Console.WriteLine("App created.");
}
catch (SquidexException ex) when (ex.StatusCode == 400)
{
Console.WriteLine("App already exists.");
}
var schemaName = "ids-test";
try
{
await client.Schemas.PostSchemaAsync(new CreateSchemaDto
{
Name = schemaName,
IsPublished = true,
});
Console.WriteLine("Schema created.");
}
catch (SquidexException ex) when (ex.StatusCode == 400)
{
Console.WriteLine("Schema already exists.");
}
var contents = client.DynamicContents(schemaName);
foreach (var id in idsList)
{
try
{
await contents.UpsertAsync(id, new DynamicData(), ContentUpsertOptions.AsPublish);
await contents.DeleteAsync(id);
try
{
await contents.GetAsync("id");
}
catch (SquidexException ex) when (ex.StatusCode == 404)
{
Console.WriteLine("Content deleted.");
}
}
catch
{
Console.WriteLine($"Failed to handle content ID {id}.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment