Skip to content

Integrating and Updating Entities

This page offers examples on integrating and updating products and content entities in Relewise.

You can find our Java SDK here.

Start by making a Tracker instance:

java
var tracker = new Tracker(
  "00000000-0000-0000-0000-000000000001",
  "your api key",
  "the server URL for the dataset");

You can read about how to authenticate against our API here

Integrating and Updating Products with Java

To get products into Relewise, follow the template laid out below. Be aware of different data types and when to use the correct one.

Add whatever fields are necessary for your integration to be useful for your search and/or recommendation requirements.

If you are unsure of what entity-actions to take, refer to our list of entity-actions.


To update or import the details of a single product you can make a TrackProductUpdateRequest.

The following request uses ProductUpdateUpdateKind.ReplaceProvidedProperties which creates a new product if the product hasn't been tracked before and else updates the properties set in the request for that product.

java
class Program {
    public static void main(String[] args) throws Exception
    {
        var tracker = new Tracker(
            "00000000-0000-0000-0000-000000000001",
            "your api key",
            "the server URL for the dataset");
    
        fullProductUpdates(tracker);
    }

    private static void fullProductUpdates(Tracker tracker) throws Exception {
        // Create a timestamp to distinguish active and inactive entities
        // Read more at
        // https://docs.relewise.com/docs/developer/bestpractices/product-integration.html
        long importedAtTimestamp = System.currentTimeMillis();

        // Language can be any string, and doesn't have to be a valid iso-standard.
        var english = Language.create("en");
        var dkk = Currency.create("DKK");

        var updates = new ArrayList<Trackable>();

        // Foreach product that needs to be imported, do the following:
        {
            // The Id should be the primary id of the product
            var product = Product.create("Product-SKU-01");

            // We only set the English translation in this example
            // but more can be set by parsing more MultilingualValue
            // to the Multilingual.create method.
            product.setDisplayName(
                Multilingual.create(
                    MultilingualValue.create(english, "The english display name")
                )
            );

            product.setSalesPrice(MultiCurrency.create(Money.create(dkk, 199.0)));
            product.setListPrice(MultiCurrency.create(Money.create(dkk, 199.0)));

            product.setBrand(
                // Displayname can be left out, but Id is required
                Brand.create("brandId")
                    .setDisplayName("Brand display name")
            );

            // We only set the English translation in this example
            // but more can be set by parsing more MultilingualValue
            // to the Multilingual.create method.
            product.addToData("ShortDescription", DataValueFactory.create(
                Multilingual.create(
                    MultilingualValue.create(english,"The short english description")
                )
            ));

            product.addToCategoryPaths(CategoryPath.create(
                CategoryNameAndId.create("74", Multilingual.create(
                    MultilingualValue.create(english, "Play")
                )),
                CategoryNameAndId.create("2", Multilingual.create(
                    MultilingualValue.create(english, "Swings")
                )),
                CategoryNameAndId.create("529", Multilingual.create(
                    MultilingualValue.create(english, "Swing Seats")
                ))
            ));

            product.addToData("ImportedAt", DataValueFactory.create(importedAtTimestamp));
            product.addToData("MinimumAge", DataValueFactory.create(4));
            product.addToData("InStock", DataValueFactory.create(true));
            product.addToData("USPs", DataValueFactory.create("first usp", "second usp", "third usp"));

            // Add any additional fields you would want returned from Relewise

            var variants = new ArrayList<ProductVariant>();

            // Foreach variant of this product
            {
                var variant = ProductVariant.create("The variant id");

                variant.addToData("Materials", DataValueFactory.create(
                    new MultilingualCollectionValue[] {
                        new MultilingualCollectionValue(
                            english, new String[] { "Wood", "Metal" }
                        )
                    }
                ));

                variant.addToData("Colors", DataValueFactory.create(
                    new MultilingualCollectionValue[] {
                        new MultilingualCollectionValue(
                            english, new String[] { "Red", "Green" }
                        )
                    }
                ));

                variant.addToData("PrimaryMaterial", DataValueFactory.create(
                    Multilingual.create(MultilingualValue.create(english, "Wood")))
                );
                variant.addToData("PrimaryColor", DataValueFactory.create(
                    Multilingual.create(MultilingualValue.create(english, "Red")))
                );

                // Add any additional fields you would want returned from Relewise

                variants.add(variant);
            }

            var productUpdate = ProductUpdate.create(product, ProductUpdateUpdateKind.ReplaceProvidedProperties);
            productUpdate.setVariants(variants.toArray(new ProductVariant[variants.size()]));
            productUpdate.setVariantUpdateKind(ProductUpdateUpdateKind.ReplaceProvidedProperties);
            productUpdate.setReplaceExistingVariants(true);
            // Replace existing variants = true will delete all variants in Relewise
            // (for the listed products) not included in this update request.

            updates.add(productUpdate);
        }
        // Foreach product END

        // If this is a full-import (not delta), disable all non-included products
        {
            // Setting this to false will make it disable all products that don't have the "ImportedAt" key.
            boolean onlyDisableOldProductsThatHaveTheImportedAtKey = true;

            boolean negated = true;
            var nonUpdatedProductFilter = FilterCollection.create(
                ProductDataFilter.create(
                    "ImportedAt",
                    ValueConditionCollection.create().setItems(
                        EqualsCondition.create(DataValueFactory.create(importedAtTimestamp), negated)
                    ),
                    true,
                    onlyDisableOldProductsThatHaveTheImportedAtKey,
                    null,
                    null
                )
            );

            var disableProductsWithoutNewestTimestamp = ProductAdministrativeAction.create(
                Language.UNDEFINED,
                Currency.UNDEFINED,
                nonUpdatedProductFilter,
                ProductAdministrativeActionUpdateKind.Disable,
                ProductAdministrativeActionUpdateKind.Disable
            );

            updates.add(disableProductsWithoutNewestTimestamp);
        }

        boolean negated = false;
        var updatedProductFilter = FilterCollection.create(
            ProductDataFilter.create(
                "ImportedAt",
                ValueConditionCollection.create().setItems(
                    EqualsCondition.create(DataValueFactory.create(importedAtTimestamp), negated)
                ),
                true,
                true,
                null,
                null
            )
        );
        var enabledProductsWithNewestTimestamp = ProductAdministrativeAction.create(
            Language.UNDEFINED,
            Currency.UNDEFINED,
            updatedProductFilter,
            ProductAdministrativeActionUpdateKind.Enable,
            ProductAdministrativeActionUpdateKind.Enable
        );

        updates.add(enabledProductsWithNewestTimestamp);

        tracker.track(BatchedTrackingRequest.create(updates.toArray(new Trackable[updates.size()])));
    }
}

Integrating and Updating Content with Java

To get content into Relewise, follow the template laid out below. Be aware of different data types and when to use the correct one.

Add whatever fields are necessary for your integration to be useful for your search and/or recommendation requirements.

If you are unsure of what entity-actions to take, refer to our list of entity-actions.

java
class Program {
    public static void main(String[] args) throws Exception
    {
        var tracker = new Tracker(
            "00000000-0000-0000-0000-000000000001",
            "your api key",
            "the server URL for the dataset");
    
        fullContentUpdates(tracker);
    }

    private static void fullContentUpdates(Tracker tracker) throws Exception {
        // Create a timestamp to distinguish active and inactive entities
        // Read more at
        // https://docs.relewise.com/docs/developer/bestpractices/product-integration.html
        long importedAtTimestamp = System.currentTimeMillis();

        // Language can be any string, and doesn't have to be a valid iso-standard.
        var english = Language.create("en");

        var updates = new ArrayList<Trackable>();

        // Foreach content element that needs to be imported, do the following:
        {
            // The Id should be some value associated to the content element
            // which does not change if titles or similar are changed.
            var content = Content.create("Content-ID-01");

            // We only set the English translation in this example
            // but more can be set by parsing more MultilingualValue
            // to the Multilingual.create method.
            content.setDisplayName(Multilingual.create(
                MultilingualValue.create(english, "The English display name"))
            );

            content.addToData("ShortDescription", DataValueFactory.create(Multilingual.create(
                MultilingualValue.create(
                    english,
                    "The short English description"
                )
            )));

            content.addToCategoryPaths(CategoryPath.create(
                CategoryNameAndId.create("23", Multilingual.create(
                    MultilingualValue.create(english, "Outdoor")
                )),
                CategoryNameAndId.create("372", Multilingual.create(
                    MultilingualValue.create(english, "Hiking")
                ))
            ));

            content.addToData("ImportedAt", DataValueFactory.create(importedAtTimestamp));
            content.addToData("ReadingTimeInMinutes", DataValueFactory.create(3));
            content.addToData("News", DataValueFactory.create(true));
            content.addToData("Badges", DataValueFactory.create("fun", "current season", "some other badge"));

            var contentUpdate = ContentUpdate.create(
                content,
                ContentUpdateUpdateKind.ReplaceProvidedProperties
            );

            updates.add(contentUpdate);
        }
        // Foreach content element END

        // If this is a full-import (not delta), disable all non-included content elements
        {
            // Setting this to false will make it disable all content elements that don't have the "ImportedAt" key.
            boolean onlyDisableOldContentElementsThatHaveTheImportedAtKey = true;

            boolean negated = true;
            var nonUpdatedContentFilter = FilterCollection.create(
                ContentDataFilter.create(
                    "ImportedAt",
                    ValueConditionCollection.create().setItems(
                        EqualsCondition.create(DataValueFactory.create(importedAtTimestamp), negated)
                    ),
                    true,
                    onlyDisableOldContentElementsThatHaveTheImportedAtKey,
                    null,
                    null
                )
            );

            var disableContentElementsWithoutNewestTimestamp = ContentAdministrativeAction.create(
                Language.UNDEFINED,
                Currency.UNDEFINED,
                nonUpdatedContentFilter,
                ContentAdministrativeActionUpdateKind.Disable
            );

            updates.add(disableContentElementsWithoutNewestTimestamp);
        }

        boolean negated = false;
        var updatedContentFilter = FilterCollection.create(
            ContentDataFilter.create(
                "ImportedAt",
                ValueConditionCollection.create().setItems(
                    EqualsCondition.create(DataValueFactory.create(importedAtTimestamp), negated)
                ),
                true,
                true,
                null,
                null
            )
        );
        var enableContentElementsWithNewestTimestamp = ContentAdministrativeAction.create(
            Language.UNDEFINED,
            Currency.UNDEFINED,
            updatedContentFilter,
            ContentAdministrativeActionUpdateKind.Enable
        );

        updates.add(enableContentElementsWithNewestTimestamp);

        tracker.track(BatchedTrackingRequest.create(
            updates.toArray(new Trackable[updates.size()])
        ));
    }
}

Don't know us? Don't worry - you can find more information about us, by visiting our main page www.relewise.com