Enable Incremental Feed API for Sitecore Discover

This blog is a quick post about the steps required to activate the incremental feed API for Sitecore Discover and how to resolve potential issues that may show up during the process.

Use Case

As a product administrator, I want to send real-time updates like product prices or stock levels to Sitecore Discover from my commerce platform. To facilitate this functionality, we want to enable the incremental data feed API of Sitecore Discover. For the blog, let’s assume we want to update the “price” attribute in Sitecore Discover via the API call.

So, let’s get started!

Pre-requisites

Step 1 – API Endpoint Link

Navigate to the CEC portal’s Developer Resources > API Access tab and locate the ‘Incremental Feed API‘ link that is unique to your instance as shown below:

Source : Sitecore Discover documentation

Step 2 – Enable Feed

Next, we must verify that our Sitecore Discover incremental feed API is enabled. To confirm this, navigate to the Sitecore CEC portal. Go to Administration > Domain Settings > General Settings > Incremental Feed and confirm it’s enabled.

If it’s not enabled, select the ‘Edit‘ icon and activate the feed adjacent to the option. Afterward, save and publish the domain settings.

Step 3 – POST call

I usually use Postman client to experiment with API calls before integrating them into an application. According to the specification, only “sku” and “attributes” are required objects. Since we are only interested in updating the “price” attribute, our Postman call may look like as following:

POST https://BASE-URL/feed/YOUR-CUSTOMER-NUMBER/v1/products/incremental/update
 {
   "data": {
        "products": [
            {
                "sku": "product123",
                "attributes": {
                    "price": "9.99"
                }
            }
        ]
    }
 }
 Header:
 Content-Type: application/json
 Authorization: "<your api-key>"

I formulated the request in the Postman client and clicked send, and I got a 400 bad request error:

Copying error message here for visibility

{
    "request-id": "d60a0dc5-999d-4909-9263-bf8ada251508",
    "error-id": "3cb5b916-0749-4019-8dd6-3dbbc09e8852",
    "code": "INVALID_ATTRIBUTE_TYPE",
    "type": "BadRequest",
    "message": "Invalid type for provided 'attribute' value",
    "data": {
        "attribute": "price",
        "expected_type": "float",
        "product_index": 0,
        "value": "9.99"
    }
}

Looking at the HTTP response status page, it became clear that I needed to pass in the price value as float and not as a string (without the double quotes), so the new request became:

POST https://BASE-URL/feed/YOUR-CUSTOMER-NUMBER/v1/products/incremental/update
 {
   "data": {
        "products": [
            {
                "sku": "product123",
                "attributes": {
                    "price": 9.99
                }
            }
        ]
    }
 }
 Header:
 Content-Type: application/json
 Authorization: "<your api-key>"

I was quite confident that it would function correctly this time, but we encountered another 400 bad request error:

{
    "request-id": "7ee019cb-1877-45c1-84ea-cf24b30e7d2f",
    "error-id": "3d7b8382-8c8f-4398-a7fe-65d9db34a068",
    "code": "ATTRIBUTE_NOT_MARKED_AS_INCREMENTAL",
    "type": "BadRequest",
    "message": "Provided 'attribute' is not marked as incremental in CEC",
    "data": {
        "attribute": "price",
        "product_index": 0
    }
}

Step 4 – Enable Attribute

After revisiting the HTTP response status code page and conducting research online, I realized that I needed to modify a setting in the CEC portal. So, once again, I navigated to the CEC portal’s Administration > Domain Settings > Attributes and selected the ‘price’ attribute as follows:

As shown below, I ticked the box for the ‘From incremental feed‘ and saved and published my changes.

I tried to update the price again via Postman, and this time it worked as I got an OK response.

I verified the updates in the CEC portal, and everything was working as expected!

The incremental data feed is enabled, and we can push “price” updates in real-time.

Please note that you can only update products that are already present in the system, to add a new product, you have to upload the complete feed. Please reference one of my previous posts to figure out how to prepare the product and category feed for Sitecore Discover

Thanks

References