Dev guideRecipesAPI ReferenceChangelog
Dev guideRecipesUser GuidesNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Sync content

How to sync your content with Optimizely Graph using the .NET Source SDK.

📘

Note

Optimizely Graph .NET Source SDK is optimized for CMS 12.

After completing the steps in the Get started and Content types articles, sync your content with Optimizely Graph.

Sync your content

To sync content, create an instance of your class object and pass it to the client. The following code example uses the Cafe class from the Get started article:

var exampleDataInstance1 = new Cafe
{
    Name = "Optimizely's Awesome Cafe",
    Established = new DateTime(2024, 06, 12),
    Address = new Location
    {
        City = "New York",
        State = "NY",
        Zipcode = "10003",
        Country = "USA"
    },
    Menu = new Menu
    {
        Beverages = new List<Beverage>
        {
            new() {
                Name = "Espresso",
                Price = 4.99,
                Sizes = new[] { "S", "M" }
            },
            new() {
                Name = "Latte",
                Price = 5.99,
                Sizes = new[] { "M", "L" }
            },
            new() {
                Name = "Cappuccino",
                Price = 6.99,
                Sizes = new[] { "S", "M", "L" }
            }
        },
        Food = new List<FoodItem>
        {
            new() {
                Name = "Bagel",
                Price = 5.25,
                IsAvaiable = true
            },
            new() {
                Name = "Croissant",
                Price = 3.89,
                IsAvaiable = true
            },
            new() {
                Name = "Cinnamon Roll",
                Price = 4.99,
                IsAvaiable = false
            }
        }
    }
};

Assign unique IDs

Each data instance requires a unique ID for identification and updates. The following example uses the cafe name and address to generate an ID. Use the SaveContentAsync method to push your content.

await client.SaveContentAsync(
    generateId: (x) => $"{x.Name}_{x.Address.City}", 
    exampleDataInstance1
);
📘

Note

Pushing content with an ID that exists in Optimizely Graph overwrites the existing content.

Push multiple objects

The .NET Source SDK syncs multiple objects in a single call when you pass an array of data instances. The following code example uses a comma-separated parameter list:

await client.SaveContentAsync(
    generateId: (x) => Guid.NewGuid().ToString(), 
    exampleDataInstance1,
    exampleDataInstance2,
    //and so on
);

Verify data

After completing the previous steps, go to the interactive GraphiQL page to run queries and retrieve your synced data. See Access the interactive GraphiQL page for instructions.

📘

Note

Remember to add your singlekey to the query parameter to access the GraphiQL page.