When doing a 'View on Site' from a Component in Tridion 8.5, the popup dialogue gives a list of pages that the the component has been published on (along with the Purposes):
I can see from Fiddler that this makes the following API call:
POST /WebUI/Models/TCM54/Services/Publishing.svc/GetListContainingPages HTTP/1.1
with the content:
{"id":"tcm:1135-11570","instruction":{"includeWorkflow":true,"resolvePublishedPagesOnly":true}}
and get the response similar to:
{
"d": "<tcm:ContainingPages xmlns:tcm=\"http:\/\/www.tridion.com\/ContentManager\/5.0\" ID=\"tcm:1135-11570\">
<tcm:Item ID=\"tcm:1135-11565-64\" Title=\"Homepage\" Path=\"\\400 Website\\Home\">
<tcm:PublishTarget TargetTypeId=\"tcm:0-1005-65538\" TargetTypeTitle=\"Staging\"
Purpose=\"Staging\" IsPublished=\"true\" PublishedAt=\"2018-07-10T14:25:27\" \/>
<\/tcm:Item>
<\/tcm:ContainingPages>"
}
I would like to emulate this behaviour in a Core Service app.
Can this be done through the Core Service API? If so, how is this achieved?
I’ve tried using Client.GetPublishUrl(ItemId, Purpose);
but this only works with Pages, Structure Groups and Publications.
I've also tried Client.GetListPublishInfo(ComponentId);
, but this only gives details if the Component is published as part of a Dynamic Component Presentation.
NOTE: I could obviously do this by recursively doing a 'Where used' on the Component(s) until I get a list of Pages and then seeing whether they're published, but was hoping that there was a simpler mechanism.
Update:
Here is the working code based on the accepted answer that Neil gave:
void Main() {
ResolveContainingPagesInstructionData instruction = new ResolveContainingPagesInstructionData() {
IncludeComponentMetadataLinks = true,
IncludeDynamicVersion = true,
IncludePageMetadataLinks = true,
IncludeWorkflow = true,
ResolvePublishedPagesOnly = true
};
ContainingPagesDictionary dictionary = Client.ResolveContainingPages("tcm:1135-11570", instruction);
dictionary.Dump();
foreach (var key in dictionary.Keys.OrderBy(k => k.Item.Title))
{
string publishUrl = Client.GetPublishUrl(key.Item.IdRef, "Staging");
Console.WriteLine($"{key.Item.Title} ({key.Item.IdRef}) - {publishUrl}");
}
}