Forum Discussion

sdujari's avatar
sdujari
Mentor
10 years ago

External Rest call of a JSON file

I am trying to make the following call - 

 

<#assign header = http.client.request("https://www.sample.com/header/html/json") />

 

to pull in our header to the community. I've placed this in the <head> section of my wrapper. I've added the domain as one of the allowed domains in Admin > System > HTTP Client but this doesn't seem to work still. Can anyone help?

  • sdujari - What you are currently doing in wrapper is actually not feasible, you can only make the http request from the Lithium Endpoints and not from custom components or wrapper. Check in your studio if the endpoints are enabled for you, or contact support if they aren't. Here is the documentation on how to use the Endpoints. Let me know if this helps.

    • sdujari's avatar
      sdujari
      Mentor

      Thanks for the help  VarunGrazitti and HaidongG .

       

      Unfortunately I still can't get it to work.

       

      I'm trying to make the following call (edited out some of the URL):

       

      <#assign header = http.client.request("https://www....com/...-header-footer/header/html/json") />

       

      And pull a json file. then I want to use ${header.main_html} to place the html on the page. I've tried making the endpoint but it doesn't seem to work or be able to pull the file, though I have no problem accessing it via my browser so I know the URL is correct.

      • HaidongG's avatar
        HaidongG
        Lithium Alumni (Retired)

        Hi sdujari 

         

        if you need to pull the html and set into "<head>", you should not use httpclient (which is not for this purpose), but URL fetcher.

         

        To do that, you need to provide the desired URL to Professional Services (or Lithium Support if post-launch), they can put a backend fetcher which fetches the content periodically and set to a community setting.

         

        After that, you may access the html via

        <#assign my_header = settings.name.get("fetch_url_key_given_by_lithium") />

         in your wrapper components.

         

         

        you may read more from http://community.lithium.com/t5/Launching-your-site/Providing-your-Lithium-design-UI-for-launch/ta-p/69314

        ...

        • The customer will be required to provide Lithium with 3 different URLs, one for the head code, one for the header and one for the footer. Additional URLs can be configured if required

        ....