Forum Discussion

bcmacdonald's avatar
9 years ago

API call to pull blog teaser and image

1. Is it possible to use API V2 (or V1) to pull blog teaser and the image.  If yes, please provide sample code (HTTP call).

2. Can the image be reformatted to a specific size using the API call?

 

Thank you in advance.

  • Hey bcmacdonald there are calls to get the teaser and blog body.

    Api V1 in a custom component on the article page like this:

    <#assign message = restadmin("/messages/id/" + page.context.thread.topicMessage.uniqueId).message />

    From there the teaser field is "message.teaser"

     

    But there's no "image" field.

    We've got a predefined format for the teaser that our team follows.
    Based on that we're parsing through the teaser to find the start and end of the specific image we want.

    A function reads in the "message.teaser" and marks the location of the "<img>" and "</>" tags. we then cut the string down to that and use it to pull the image out of the teaser.

     

    If you have an image in the post body you could do the same. But you'd need to make sure your code allows for other tags that could appear before the image.

     

    Tim

     

  • ChhamaJ's avatar
    ChhamaJ
    Khoros Staff

    Hi Brian,

     

    There is definitely a way to get blog teaser and image using API V2

     

    Select * from messages where id ='1'

     

    Just pass in the id for the blog and in the response you would see fields for Teaser and images.

     

    As for updating the image size via an API call, unfortunately we do not support it yet. We only support updating the title and description of the image via API. May be a good candidate for our Idea Board ?

     

    Hope this helps.

     

    Regards,

    Chhama

    • ethanede's avatar
      ethanede
      Helper

      When doing an API call for messages with the label text "Events", I do see a field for teaser, but the value returned is one string:

      "teaser" : "<P>&nbsp;<span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 480px;\"><img src=\"https://stage.liveopsnation.com/t5/image/serverpage/image-id/74iEAC9E1BB2EE4DFE6/image-size/large?v=1.0&amp;px=999\" alt=\"youcandoit.png\" title=\"youcandoit.png\" /></span></P>\n<P>This is the article teaser.</P>"

      Accessing the image is not straightforward as it would if there were keys for each element of the string. So how do I return just the URL for the image and, separately, just the actual text from the teaser? String gymnastics? What's the best way to do this? Anyone have a code example?

      • Parshant's avatar
        Parshant
        Boss

        ethanede

        After API call you will get teaser node

        "teaser" : "<P>&nbsp;<span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 480px;\"><img src=\"https://stage.liveopsnation.com/t5/image/serverpage/image-id/74iEAC9E1BB2EE4DFE6/image-size/large?v=..." alt=\"youcandoit.png\" title=\"youcandoit.png\" /></span></P>\n<P>This is the article teaser.</P>"

        Assign this teaser value into a variable like this in your <#list></#list>

         

         

        <#assign messageTeaser = message.teaser?split("<img","i") >
        <#assign messageTeaser?lower_case?contains("<img")>
        <#assign images = messageBody?split("<img","i") >
        <#assign getImageUrl = images[1]?split(" />","i") >
        <#assign getImage="<img class='img' "+getImageUrl[0]+" />" />
        ${getImage}

         

        Above code is to get first image from teaser.

        If you want multiple images from teaser you can use

        ${images} in list
        <#list images as image>

        this will return all images from teaser under list