Forum Discussion

smogger914's avatar
9 years ago

Component with endpoint and 3rd party REST API

Hey,   I am trying to build a component that does a callout to a 3rd party rest api. I can get a JSON response using POSTMAN with that url. I have build out the endpoint like this:   <#assign bas...
  • luk's avatar
    9 years ago

    Regarding your endpoint code (see comments):

    <#assign baseUrl = "http://success.mindtouch.com/@api/deki/site/search?q=sso&limit=2&dream.out.format=json"/>
    <#assign req = http.client.request(baseUrl) />

    <#-- if you actually want to use the response with FreeMarker, the JSON has to be converted to a FreeMarker hash like that -->
    <#assign req = req.json() />
    <#-- but careful, if you do that, you cannot simply print the response JSON string with ${...} anymore as FreeMarker hashes are not auto-convertable to strings (e.g. JSON) -->
    <#assign response = req.call("GET") /> <#-- shouldn't this be get(), where did you find that call() method? --> <#assign response = req.get() />

    <#-- for above see http://community.lithium.com/t5/Developers-Knowledge-Base/http-client-FreeMarker-Context-Object/ta-p/80614 --> <#-- and then to output the response you have to do something like --> ${response.content}

    <#-- see http://community.lithium.com/t5/Developers-Knowledge-Base/http-client-response-FreeMarker-context-object/ta-p/80622 -->

    and make sure the MIME type of the endpoint is set to JSON.

     

    From the code you provided I cannot see if you are actually outputting something in the endpoint?