Forum Discussion
Hi AdamN
Thanks for your response, i am halfway in which I am able to pass the value to the endpoint via custom component, but I am somehow not able to use it inside the endpoint. Below is the change I made to the endpoint code after your suggestion.
Endpoint:
<#compress> <#assign search_query = http.request.parameters.name.get("query", "")> <#attempt> <#assign response = http.client.request("https", "abc:xyz@123.zendesk.com","/api/v2/search.json?query=%5C%22${search_query}%5C%22").get() /> <#recover> <!-- Something --> </#attempt> </#compress>
Custom Component Code to pass the value to the parameter
$.get( "${kb_endpoint_url}", { search_query : queryValue } )// where queryValue is being passed from a text box .done(function( data ) {...
When I checked in the firebug, the request was a Success but returened below reponse:
Uncaught TypeError: Cannot read property 'results' of null
Do you find any loops here?
Hi Gursimrat
can you try to replace the URL with this?
<#assign response = http.client.request("https", "abc:xyz@123.zendesk.com","/api/v2/search.json?query='${search_query}'").get() />
I think the issue is that the http.client is always trying to encode your URL so if you specify an encoded query you will get a double encoded one :)
This is just a guess though..
Thanks,
Nico
- Gursimrat11 years agoLeaderStill giving same error :(
- NicoB11 years agoLithium Alumni (Retired)
Hi Gursimrat
could you please post the code in your <#recover> section?
What I don't understand is where you are trying to access the results variable since I cannot see any such variable in your code and I think that's where the issue is happening.
Thanks,
Nico
- Gursimrat11 years agoLeader
Hi NicoB
results are basically the JSONP response I am trying to read. And adding the code to recover didn't help.
{"count":1,"results":[{"result_type":"article","position":0,"comments_disabled":false,"label_names":[],"vote_sum":0,"locale":"en-us","section_id":200164994,"url":"https://community-name.zendesk.com/hc/api/v2/articles/200820164-What-are-these-sections-and-articles-doing-here-.json","id":200820164,"html_url":"https://community.zendesk.com/hc/en-us/articles/200820164-What-are-these-sections-and-articles-doing-here-","draft":false,"source_locale":"en-us","title":"What are these sections and articles doing here?","updated_at":"2014-02-07T23:46:17Z","promoted":false,"name":"What are these sections and articles doing here?","created_at":"2014-02-07T23:46:17Z","translation_ids":[201089774],"author_id":243252074,"vote_count":0}],"previous_page":null,"facets":null,"next_page":null}
Workflow is as below:
From a text box in the custom component, when a user enters a query, and on the click of the search button, the parameter will be passed on to the endpoint. The endpoint will then call the external zendesk API via http request and the returned results will be served to custom component which will display them on the forums.