1

Is there any way to pass a parameter to the Item Web API so that it maintains the structure of the items its returning in the JSON? For example, I am pulling back Questions and Answers, but right now I have no way of knowing which answers belong to which questions, since the JSON is flat. It would be nice if the JSON replicated the structure of my Sitecore Tree and had the Answers nested beneath the Questions.

The Current Structure (simplified):

{
    template: 'sitecore/question',
    title: 'Question 1'
},
{
    template: 'answer',
    title: 'My first answer'
}

Intended Structure:

{
    template: 'sitecore/question',
    title: 'Question 1',
    items:     
       {
           template: 'answer',
           title: 'My first answer'
       }
}

2 Answers 2

1

To my knowledge there is no such functionality.

You could do one of the following:

  1. Implement your own functionality for this by modifying the itemWebApiRequest pipeline.
  2. Make new requests for each question to get the individual answers.
  3. Implement logic on the receiving end parsing the "LongId" or "Path" field and find the relationships that way.
Sign up to request clarification or add additional context in comments.

2 Comments

I am going about a hybrid of #1 and #3, attempting to parse the Path and create that nesting. Im hoping that by doing it through the pipeline, I can keep the flexibility that initially sold me on the Web API. I do find it very odd that this functionality was omitted though, as Sitecore is such a hierarchy-driven product.
If you find a nice solution for it, please let us know. Here or in a blog post.
0

You can probably write your own class to get the results tailored to what you need. If you look at the configuration of the api you can see that you can tap into the pipeline.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.