Forum Discussion

hayata's avatar
5 years ago

http.client request error

I am trying to make a call something like this:

<#assign response = http.client.request("https://example.com/rest/search/token").header("Authorization", "Bearer zzzzxxxxeeeyyyzzz").header("content-type", "application/json").body('{"userIds":[{"name": "testuser","provider": "test"}], "search": "search"}',"application/json").post()/>

But, I am getting an error:

An error has occurred when reading existing sub-variable "client"; see cause exception! The type of the containing value was: extended_hash+string (lithium.coreapi.webui.template.models.HttpTemplateModel wrapped into f.e.b.StringModel)

What does this error mean?

  • Hi hayata ,

    It seems a syntax error. for using http.client.request the "https" and "URL" are two different parameters.

    you may need to pass something like:

    <#assign http_client_request = http.client.request("http", "www.somewebservicedomain.com", "/some/web/service") />

    Documentation for the same can be found over here:

    https://developer.khoros.com/khoroscommunitydevdocs/reference/httpclientrequest#httpclientrequesturl

     

    Please Give Kudos if you find this post useful and also mark this as Accepted Solution if this is the required solution.

    Regards

    Tarun Kumar

  • Tarun I tried it and it still encounters the same error.  The doc says it supports both approaches.

  • Here is a code example from the documentation:

    <#assign http_client_request = http.client.request("http", "www.somewebservicedomain.com", "/some/web/service").body("{ 'application':'lithium', 'user':'johnD' }", "application/json").post() />

    Maybe Khoros only support plain object in body parameter. You can change your body parameter with a plain object and see if you can send out the payload. 

     

  • peterlu  Thanks for the example.  I still get the same error.

    I deconstructed the call to this:

     

    <#assign http_client_request = http.client.request("http", "ww.somewebservicedomain.com", "/some/web/service")/>

     

    It's literally the above with sample domain and endpoint.  Since it is just setting up the object, the values shouldn't matter.

    But I still get the same error when I save.

    An error has occurred when reading existing sub-variable "client"; see cause exception! The type of the containing value was: extended_hash+string (lithium.coreapi.webui.template.models.HttpTemplateModel wrapped into f.e.b.StringModel)

     

    BTW, the code I am using is copied from an another Khoros customer instance and it works.

    Does it seem like a bug in the http library?

     

     

    • peterlu's avatar
      peterlu
      Champion

      hayata If the code works in one instance, but not on another, then you can lodge a support ticket to Khoros. But before you send the ticket, please check all the necessary set up, eg. domain whitelisting etc.

  • peterlu Thanks.  I checked everything I could think of.  The API call works in Postman from my personal home computer, so I know it's not the target server blocking requests.  I also checked the Khoros setting for outbound calls and it is set although I have no way of testing.  I created the ticket with support.