Forum Discussion

Inactive User's avatar
Inactive User
6 years ago

Url has one id, page.context.message.id is a different ID??

When I use the API browser for the URL id, t5/Discussions/How-about-a-Jelly-baby/m-p/7973 [id: 7973],  I get the correct results I'm looking for. However, when I use page.context.message.id => '272', which is a completely different message! What's going on here, any ideas before I open a support ticket? Are there IDs and Unique IDs and are they getting mixed up?

I'm trying to get the ID to look up the cover_image and images array for an Open Graph component. But failing because of this.

Ian

 

<#-- OPEN GRAPH -->
<#macro setOGProps msgs imgs>
<#if msgs?? && msgs[0].cover_image??>
<!-- msgs cover image OK -->
<#assign ogImgUrl=msgs[0].cover_image.large_href />
<#else>
<#if images??>
<!-- images exist? ${images???c} -->
<!-- images size ${images?size} -->
<#if images?size gt 0>
<!-- images size ${images?size} -->
<#assign ogImgUrl=images[0].large_href />
<#else>
<#assign ogImgUrl="https://www.jmp.com/content/dam/jmp/media/JMP-Open-Graph-Default.jpg"/>
</#if>
<!-- default cover image -->
</#if>
</#if>
<!-- OPEN GRAPH CONTENT -->
<meta property = "og:title" content = "${page.content.body.title}"/>
<meta property = "og:image" content = "${ogImgUrl}"/>
<meta property = "og:url" content = "${msgs[0].view_href}"/>
<meta property = "og:description" content = "${msgs[0].subject}"/>
<meta property = ”og:type” content = ”website”/>

</#macro>
<#if env.context.message??>
<!-- env.context.message -->
<!-- env.context.message.id ${page.context.message.id} -->
<#assign msgQuery = "SELECT cover_image, view_href, subject FROM messages WHERE id='${env.context.message.id}'"/>

<#assign msgs = rest("2.0", "/search?q=" + msgQuery?url + "&restapi.response_style=view").data.items![] />
<#assign imgQuery = "SELECT view_href, title FROM images WHERE messages.id='${env.context.message.id}'"/>
<#assign images = rest("2.0", "/search?q=" + imgQuery?url + "&restapi.response_style=view").data.items![] />
<#--<p>${images?size}</p>-->

<@setOGProps msgs=msgs imgs=images></@setOGProps>

</#if>
<#if page.context.message??>
<!-- page context message -->
<#--<!-- page.context.thread.topicMessage.id ${page.context.thread.topicMessage.id} &ndash;&gt;-->
<!-- page.context.message.id ${page.context.message.id} -->
<#assign threadQuery = "SELECT cover_image, view_href, subject FROM messages WHERE id='${page.context.message.id}'"/>
<#assign msgs = rest("2.0", "/search?q=" + threadQuery?url + "&restapi.response_style=view").data.items![] />
<#assign imgQuery = "SELECT view_href, title FROM images WHERE messages.id='${page.context.message.id}'"/>
<#assign images = rest("2.0", "/search?q=" + imgQuery?url + "&restapi.response_style=view").data.items![] />
<#--<p>${images?size}</p>-->
<@setOGProps msgs=msgs imgs=images></@setOGProps>
</#if>

  • Hi Inactive User ,

    Try "uniqueId" instead of "id".

    The "uniqueId" is a community-wide unique message id and corresponds to what you're seeing in the URL. The "id" is a board-specific message id.

  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi Inactive User ,

    Try "uniqueId" instead of "id".

    The "uniqueId" is a community-wide unique message id and corresponds to what you're seeing in the URL. The "id" is a board-specific message id.

    • Inactive User's avatar
      Inactive User

      Thanks, I must've missed that in the context objects docs. 

      • AdamN's avatar
        AdamN
        Khoros Oracle

        Hi TreyWaddell ,

        page.context.message.id should always give a node-relative message id, whereas page.context.message.uniqueId should always give a globally unique message id.

        The thing to be careful about is which message is actually in context. This is typically dependent on the page URL. So within a thread, there are URLs that correspond to each individual message (i.e. permalink). And if you use that URL, that will be the message in context.

        If you always want the root/topic message regardless of which message is in context, you can try to use page.context.thread instead of page.context.message. More details on that here: https://developer.khoros.com/khoroscommunitydevdocs/reference/page-1

        You could also get the root/topic from the page.context.message by doing something like: page.context.message.discussion.topicMessage