Show ContentReference details in Content API response

Vote:
 

I have Content Delivery API set up which works fine. However I have below need:

My Page type has a Content Reference property that takes a specific Block type. Currently when I fetch the page, I get this property value as null.

How do I show the details of Block properties in the response:

Ex: PageType --> NewsPage which has a Content Reference property as MediaData that takes a BlockType as VideoBlock.

I need to be able to show the properties of VideoBlock when the page is queried or fetched.

#221122
Apr 14, 2020 2:21
Vote:
 

Hi Dileep,

What version of Content Delivery API are you using?

Tested with Alloy and Content Delivery API 2.10.0 content reference works as you describe.

For example, add a new property like this to 'StandardPage' on Alloy MVC sample site:

[AllowedTypes(new Type[] { typeof(EditorialBlock) })]
[Display(GroupName = SystemTabNames.Content, Order = 500)]
public virtual ContentReference ReferenceBlock { get; set; }

Now for example on the 'Management' page select a block to this new property and publish the page. Then use content delivery API to get the page, the 'ReferenceBlock' property is rendered to the response like this:

"referenceBlock": {
  "id": 76,
  "workId": 0,
  "guidValue": "7d7635dd-499b-4f54-aa59-6b5b14756a84"
}

To get the information about the actual block in one call you need to add the query string parameter expand=propertyname, like ?expand=referenceblock and you would get response like this:

"referenceBlock": {
	"id": 76,
	"workId": 0,
	"guidValue": "7d7635dd-499b-4f54-aa59-6b5b14756a84",
	"expanded": {
		"contentLink": {
			"id": 76,
			"workId": 0,
			"guidValue": "7d7635dd-499b-4f54-aa59-6b5b14756a84"
		},
		"name": "Collaboration made simple - When and Where",
		"language": {
			"displayName": "English",
			"name": "en"
		},
		"existingLanguages": [
			{
				"displayName": "English",
				"name": "en"
			}
		],
		"contentType": [
			"Block",
			"EditorialBlock"
		],
		"parentLink": {
			"id": 69,
			"workId": 0,
			"guidValue": "8c5e76a1-1733-4f13-9e6c-e5840818a410",
			"url": "/globalassets/events/"
		},
		"changed": "2020-03-22T10:43:16Z",
		"created": "2012-10-02T12:12:19Z",
		"startPublish": "2017-11-27T07:33:11Z",
		"saved": "2020-03-22T10:43:16Z",
		"status": "Published",
		"category": [],
		"mainBody": "<hr />\n<h3>When and where?</h3>\n<p>Start: 09/10/2012 3:00:00 PM<br />End: 09/11/2012 3:30:00 PM<br />Address: Mandalay Bay Las Vegas</p>"
	}
}
#221157
Apr 14, 2020 16:26
Vote:
 

Perfect Antti. This works. Wasn't sure if the expand also works on content reference. Thought it only works on ContentArea. I wish I could have tried it before posting the question :)

#221161
Apr 14, 2020 21:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.