Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev guideRecipesAPI Reference
Dev guideUser GuidesLegal TermsNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Sync content

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

After completing the steps in the Get started and Content types articles, you can 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 you created in the Get started with the Optimizely Graph .NET Source SDK documentation:

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 unqiue ID for identification and updating. 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 the same ID overwrites it.

Push multiple objects

The .NET Source SDK supports syncing multiple objects simultaneously by passing an array of data instances. The following code example shows this with 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, you can go the interactive GraphiQL page to run queries and retrieve your synced data. See Access the interactive GraphiQL page for instructions on accessing the page.

📘

Note

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