0

How to customize Sitecore layout service json response completely by removing even Sitecore, context and route level and only return the custom data in the response?

For one of my POCs, I have the requirement to return the following result when we invoke the layout service API.

{
  "pageid": 1,
  "backgroundimagetype":"link/base64",
  "backgroundimage": null,
  "backgroundimagealttext":"Header",
  "tenantid": 1,
  "countryid": 1,
  "countryname": "Switzerland",
  "languageid": 1,
  "languagecode": "ENG",
  "icon":{
      "type":"anchor/image/base64",
      "attributes":[
        {
          "name":"href",
          "value":"#"
        },
        {
            "name":"class",
            "value":"d-block"
        }
      ],
      "subtype":"image/text",
      "subtypeattributes":[
        {
          "name":"src",
          "value":"#"
        },
        {
            "name":"class",
            "value":"d-block"
        },
        {
            "name":"alt",
            "value":"arrow"
        }
      ]
  }
  1. I have the login page which contains only fields.
  2. If I simply invoke the API then the result should be as above without even Sitecore, Context, and Route nodes. Is it possible to achieve this? If yes how I can achieve it? Someone can please help with this?

API that I'm hitting is: https://sc1010.sc/sitecore/api/layout/render/jss?item={97479C6B-BB30-4A15-AFD1-2C89F207E9D6}&sc_lang=en&sc_apikey=35537f26-6b0a-4a4f-8b76-02d823e4a4fe

Version: Sitecore 10.1

0

This was useful for me in customizing the response: https://jss.sitecore.com/docs/techniques/extending-layout-service/extending-layout-service-overview.

But, be very careful with it. It may break other JSS functionality here if you change it too much, which it looks like you want to. Adding fields is alright but changing the item serialization may take you in to holes you can't dig out of

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.