Forum Discussion

bpliskow's avatar
7 years ago

Challenges with Endpoint, Component, and External REST API Request and Variable Declaration

Hello Community!

 

I'm going to do my best to explain my current challenge. First, I'll start with the objective....

 

We have an external data which stores information about users. The primary key is the user's email address which we can obtain easily by calling the Lithium API endpoint (user.email). Our objective is to leverage specific attributes obtained from the external data store to display information w/n a component. For example, we might mark a customer for 'Enhanced Support' in our external data source and need to show the related support options to them within a custom component.

 

Now the problem...

 

There are various variations of these variables, so using a template (.tmpl) doesn't seem to meet our use case because within these you cannot define an if/then/else or case statement. However, I also can't find how to set variables server-side from within the endpoint (ftl) that make these available to be called from the custom component. I've been able to complete declaring the variables client-side with JS, but, of course, that can't be accessed server-side.

 

I hope this makes sense...now, does anyone have any thoughts on how to workaround/solve this problem?

  • ClaudiusH's avatar
    ClaudiusH
    Khoros Alumni (Retired)

    Can you share some more architecture details on which module is calling which? I'm not sure I understand "client" and "server" terminology in the context of your scenario.

    Do you want to populate that component during page load or will the information from your external data warehouse be dynamically called from JS on the page after it has loaded? This will determine the approach and technology to use.

     

    You can pass parameters to a custom component and you can use this for modals as well: https://community.lithium.com/t5/Developer-Knowledge-Base/Passing-Parameters-to-a-Custom-Component/ta-p/88704
    Also a somewhat related discussion on how to pass information from a custom component to an endpoint is discussed here: https://community.lithium.com/t5/Developer-Discussion/Passing-parameter-from-custom-component-to-an-endpoint/m-p/134595#M5208

    • bpliskow's avatar
      bpliskow
      Adept

      Hello ClaudiusH -

       

      Thanks for jumping in to help. I'll do my best to explain - my Lithium-specific terminology is admittedly not the best.

       

      We have a component which currently uses Lithium-assigned roles in an if/then/else statement to display other components.

       

      A basic view is the following:

       

      <#if user_is_in_role >
          <@component id="Component1a" />
      <#else>
          <@component id="Component1b" />
      </#if>

      This has been working well, except that we're using the Lithium role definitions to assign a value to the 'user_is_in_role' variable. We're now working to replace the role-based variable assignment with an external data source making RESTful API calls with http.client. This is where we run into challenges.

       

      We can successfully make the requests and compile the JSON results in an endpoint. However, where we're getting stuck is assigning the variables so that they can be referenced within if/then/else statements in the primary component. It sounds very similar to the second post you shared, but in reverse order where assigning the variable in the endpoint is returning a null response from the component.

       

      • ClaudiusH's avatar
        ClaudiusH
        Khoros Alumni (Retired)
        Ideally you would leave the role based branching intact and instead have the REST API call to your data source set the role instead.
        How often do these roles change? How quick do they need to update? You would want to avoid checking via a REST call against your source every time this page is loading. Maybe it's sufficient to perform this check every time a user signs in to your community?