Forum Discussion

Kev_B's avatar
Kev_B
Advisor
6 years ago

Pulling community data to an external site

Hi,

Hoping this is a simple enough request, but a search didn't yield any results to help explain what needs to be done.

Our organisation would like to pull some community threads into a module on a non-community web page. I'm familiar with the API calls to build what they need, but I've not done so for the data to be external to community and therefore making those calls on the community API.

Does anybody have any experience of doing this? If so, could you provide any practical tips for what would need to be done? Do I still use FreeMarker, or would it need to be done like an AJAX request since it's on a different server to community?

Thanks in advance,

Kev

  • Kev_B 

    > Building outside of the platform do I still use FreeMarker, or do I need to make calls back to the API (like an AJAX call etc) and handle the response before using the data?

    You can do both, e.g. talk directly to the API via JavaScript/AJAX, but then you have to deal with OAuth/session keys to authenticate against the API, which is slightly annoying 😃... But depending on the data you want to fetch it might be necessary...on the other hand if it is simply a list of topics that are visible to anybody anyways, you can save yourself the hassle. That means you just build your custom component with FreeMarker as you are used to, make it output HTML, then add the component to a custom endpoint and then fetch that endpoint via AJAX from the external site, that's the easiest way. You can also just aggregate the data you need and output JSON from the endpoint, then fetch that JSON data via AJAX and render it via JavaScript directly on the external site....

    > Is there a specific URL to use or can I still use an LiQL query when calling from an external platform?

    Yeah, something like https😕/api.lithium.com/community/2.0/<communityid>/search?q=SELECT+*+FROM+messages+WHERE+replies.count(*)%3D0&api.pretty_print=true

    see: https😕/community.khoros.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv2&v2.main=gettingstarted

    > How do I pass the API key when making the call?

    Depending on the API version you want to use you have to either negotiate a session key (v1) or an OAuth token (v2) with the API.

7 Replies

  • Kev_B's avatar
    Kev_B
    Advisor
    6 years ago

    Hi Payal 

    Thanks for this - I've taken a look and I don't think ActiveCasts quite cover what we're hoping to achieve.

    I'm more interested in using the REST API to build components (as I would do in community), but to pull that data into an external site. Just curious about the prerequisites to ensure the request is structured correctly and returns a valid response from the Khoros servers.

    If anybody has experience of doing similar and could shed some light on it that would be fantastic!

  • Kev_B's avatar
    Kev_B
    Advisor
    6 years ago

    Thanks StanGromer 

    I've done stuff with the API's in the past and if I needed to build this within our community it wouldn't be a problem.

    I'll try to list the questions I can think of and see if that helps to explain things:

    • Building outside of the platform do I still use FreeMarker, or do I need to make calls back to the API (like an AJAX call etc) and handle the response before using the data?
    • Is there a specific URL to use or can I still use an LiQL query when calling from an external platform?
    • How do I pass the API key when making the call?

    Thanks in advance 🙂

  • luk's avatar
    luk
    Boss
    6 years ago

    Kev_B 

    > Building outside of the platform do I still use FreeMarker, or do I need to make calls back to the API (like an AJAX call etc) and handle the response before using the data?

    You can do both, e.g. talk directly to the API via JavaScript/AJAX, but then you have to deal with OAuth/session keys to authenticate against the API, which is slightly annoying 😃... But depending on the data you want to fetch it might be necessary...on the other hand if it is simply a list of topics that are visible to anybody anyways, you can save yourself the hassle. That means you just build your custom component with FreeMarker as you are used to, make it output HTML, then add the component to a custom endpoint and then fetch that endpoint via AJAX from the external site, that's the easiest way. You can also just aggregate the data you need and output JSON from the endpoint, then fetch that JSON data via AJAX and render it via JavaScript directly on the external site....

    > Is there a specific URL to use or can I still use an LiQL query when calling from an external platform?

    Yeah, something like https😕/api.lithium.com/community/2.0/<communityid>/search?q=SELECT+*+FROM+messages+WHERE+replies.count(*)%3D0&api.pretty_print=true

    see: https😕/community.khoros.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv2&v2.main=gettingstarted

    > How do I pass the API key when making the call?

    Depending on the API version you want to use you have to either negotiate a session key (v1) or an OAuth token (v2) with the API.

  • HI Kev_B ,

    I've done it using the endpoint in studio. Use a freemarker to create the API that returns json format. The external website will call the API and read the data from there,

     

  • Kev_B's avatar
    Kev_B
    Advisor
    6 years ago

    luk lovely clear and concise answer, exactly what I need to know, thank you ðŸ˜ƒ