Pulling community data to an external site
- 6 years ago
> 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
> 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.