Missing Content in Content REST API

I am attempting to create my first component after integrating BloomReach with my Angular SPA. However, after I author and publish the component, the “content” portion of the component in the Content REST API does not contain the properties configured in the content document. So my Angular app is unable to display the content. In the Content REST API, the component is present in the “page” and “content” sections of the json response. But it is missing any associated content properties (for example, title, image, description, etc…). I can, however, see the configured content in the cms console. I tested this with the Essentials Banner component, and it is broken in the same way.

This is preventing me from even beginning development in BloomReach, so any suggestions would be greatly appreciated!

This development is for Shift7. We are an official BloomReach partner.

Below is the json response when I access site/resourceapi:

{
"id": "r3",
"_links": {
    "self": {
        "href": "http://localhost:8080/site/resourceapi"
    },
    "site": {
        "href": "/site/"
    }
},
"page": {
    "id": "r3",
    "name": "homepage",
    "componentClass": "org.hippoecm.hst.core.component.GenericHstComponent",
    "type": "COMPONENT",
    "components": [
        {
            "id": "r3_r1",
            "name": "main",
            "componentClass": "org.hippoecm.hst.core.component.GenericHstComponent",
            "type": "COMPONENT",
            "components": [
                {
                    "id": "r3_r1_r1",
                    "name": "container",
                    "componentClass": "org.hippoecm.hst.pagecomposer.builtin.components.StandardContainerComponent",
                    "type": "CONTAINER_COMPONENT",
                    "label": "Home Page Main",
                    "components": [
                        {
                            "id": "r3_r1_r1_r1",
                            "name": "banner",
                            "componentClass": "org.onehippo.cms7.essentials.components.EssentialsBannerComponent",
                            "type": "CONTAINER_ITEM_COMPONENT",
                            "label": "Banner",
                            "models": {
                                "document": {
                                    "$ref": "/content/u895fb1b6410d497298946b6a06d2b361"
                                }
                            },
                            "_meta": {
                                "paramsInfo": {
                                    "document": "banners/banner1"
                                },
                                "params": {
                                    "document": "banners/banner1",
                                    "org.hippoecm.hst.core.component.template": "webfile:/freemarker/hstdefault/essentials-banner.ftl"
                                }
                            },
                            "_links": {
                                "componentRendering": {
                                    "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r1_r1_r1"
                                }
                            }
                        },
                        {
                            "id": "r3_r1_r1_r2",
                            "name": "homepage-hero",
                            "componentClass": "com.gms.cms.components.BasicComponent",
                            "type": "CONTAINER_ITEM_COMPONENT",
                            "label": "Homepage Hero Component",
                            "models": {
                                "document": {
                                    "$ref": "/content/ud9b16880139e4db0bd50b6fd61c9f27c"
                                }
                            },
                            "_meta": {
                                "paramsInfo": {
                                    "document": "homepage-hero"
                                },
                                "params": {
                                    "document": "homepage-hero"
                                }
                            },
                            "_links": {
                                "componentRendering": {
                                    "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r1_r1_r2"
                                }
                            }
                        }
                    ],
                    "_meta": {
                        "params": {}
                    },
                    "_links": {
                        "componentRendering": {
                            "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r1_r1"
                        }
                    }
                }
            ],
            "_meta": {
                "params": {}
            },
            "_links": {
                "componentRendering": {
                    "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r1"
                }
            }
        },
        {
            "id": "r3_r2",
            "name": "menu",
            "componentClass": "org.onehippo.cms7.essentials.components.EssentialsMenuComponent",
            "type": "COMPONENT",
            "models": {
                "menu": {
                    "name": "main",
                    "siteMenuItems": [
                        {
                            "depth": 0,
                            "repositoryBased": false,
                            "name": "home",
                            "expanded": true,
                            "selected": true,
                            "parameters": {},
                            "childMenuItems": [],
                            "_links": {
                                "site": {
                                    "href": "/site/",
                                    "type": "internal"
                                }
                            }
                        }
                    ],
                    "selectSiteMenuItem": {
                        "depth": 0,
                        "repositoryBased": false,
                        "name": "home",
                        "expanded": true,
                        "selected": true,
                        "parameters": {},
                        "childMenuItems": [],
                        "_links": {
                            "site": {
                                "href": "/site/",
                                "type": "internal"
                            }
                        }
                    }
                }
            },
            "_meta": {
                "paramsInfo": {
                    "siteMenu": "main"
                },
                "params": {
                    "selectedMenu": "on",
                    "level": "1",
                    "menu": "main"
                }
            },
            "_links": {
                "componentRendering": {
                    "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r2"
                }
            }
        },
        {
            "id": "r3_r3",
            "name": "top",
            "componentClass": "org.hippoecm.hst.pagecomposer.builtin.components.StandardContainerComponent",
            "type": "CONTAINER_COMPONENT",
            "label": "Top",
            "_meta": {
                "params": {}
            },
            "_links": {
                "componentRendering": {
                    "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r3"
                }
            }
        },
        {
            "id": "r3_r4",
            "name": "footer",
            "componentClass": "org.hippoecm.hst.core.component.GenericHstComponent",
            "type": "COMPONENT",
            "components": [
                {
                    "id": "r3_r4_r1",
                    "name": "container",
                    "componentClass": "org.hippoecm.hst.pagecomposer.builtin.components.StandardContainerComponent",
                    "type": "CONTAINER_COMPONENT",
                    "label": "Footer",
                    "_meta": {
                        "params": {}
                    },
                    "_links": {
                        "componentRendering": {
                            "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r4_r1"
                        }
                    }
                }
            ],
            "_meta": {
                "params": {}
            },
            "_links": {
                "componentRendering": {
                    "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3_r4"
                }
            }
        }
    ],
    "_meta": {
        "definitionId": "hst:pages/homepage",
        "pageTitle": "Home Page",
        "params": {}
    },
    "_links": {
        "componentRendering": {
            "href": "/site/resourceapi?_hn:type=component-rendering&_hn:ref=r3"
        }
    }
},
"content": {
    "u895fb1b6410d497298946b6a06d2b361": {
        "id": "895fb1b6-410d-4972-9894-6b6a06d2b361",
        "_links": {
            "site": {
                "href": "/site/",
                "type": "internal"
            }
        },
        "name": "banner1",
        "displayName": "banner1",
        "localeString": "en"
    },
    "ud9b16880139e4db0bd50b6fd61c9f27c": {
        "id": "d9b16880-139e-4db0-bd50-b6fd61c9f27c",
        "_links": {
            "site": {
                "href": "/site/",
                "type": "internal"
            }
        },
        "name": "homepage-hero",
        "displayName": "Homepage Hero",
        "localeString": "en"
    }
}

}

Update: It looks like the content is being pulled from nodes beneath workspace instead of referencing the content document itself.

FYI, I just confirmed with the poster (by phone) that this is running on brXM 12.5.1-1.

Please refer to https://documentation.bloomreach.com/library/concepts/spa-plus/page-model-api/introduction.html Note that the API you are using here is called the Page Model API. There’s a different, older API that is typically referred to as the Content REST API. They behave differently.

The representation you see under the content section of the JSON response is based on the Java “content bean” class that represents the document during processing. This is added to the HstRequest by a component via the Model Contribution API, and then serialized to JSON for the response. Perhaps your component was not adding the model to the request?

related part on above page is:

" Note that the real content representation of the contributed document content item model is not included directly inside the models field. Instead it contains only a JSON Pointer referece as JSON String ("$ref":"/content/u895fb1b6410d497298946b6a06d2b361"), by which you can find the real content item representation under the content top level field by the key. Also, a component representation may include metadata, links and other model representations such as menu."

Hi, @PCentgraf and @machak ! Thanks for the replies!

I do see the JSON pointer that you’re referring to. The problem is, the content section that it points to is missing the content that has been configured in the cms.

Here is the section of code where I am assigning the content bean. The line that calls “setContentBeanForPath” is the line that adds the document reference to the model. Is there anything additional that I need to do to make the content available to the Page Model API? (Note: I had to remove the at symbol before the annotations.)

package com.gms.cms.components;

import com.gms.cms.beans.HomepageHero;
import com.gms.cms.info.BasicComponentInfo;
import com.google.common.base.Strings;
import java.util.logging.Level;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.commons.lang3.StringUtils;
import org.hippoecm.hst.container.RequestContextProvider;
import org.hippoecm.hst.content.beans.standard.HippoBean;
import org.hippoecm.hst.content.beans.standard.HippoDocument;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.core.parameters.ParametersInfo;
import org.hippoecm.hst.core.request.HstRequestContext;
import org.onehippo.cms7.essentials.components.CommonComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * author sarahshearer
 */


ParametersInfo(type = BasicComponentInfo.class)
public class BasicComponent extends CommonComponent {

    private static final Logger LOGGER = LoggerFactory.getLogger(BasicComponent.class);

    Override
    public void doBeforeRender(HstRequest request, HstResponse response) {
        super.doBeforeRender(request,response);
        BasicComponentInfo info = getComponentParametersInfo(request);
        if(StringUtils.isNotBlank(info.getDocument())) {
            LOGGER.debug("Calling BasicComponent for document path:  [{}]", info.getDocument());
            this.setContentBeanForPath(info.getDocument(), request, response);
        }
    }
}

I also tried using

request.setModel("bean", bean);

with the content bean that I obtained from the HstRequestContext. That just created a reference to the same empty content section.

For reference:

turns out this was caused by missing bean mappings config:

1 Like