Forum Discussion
Gursimrat
Leader
This is not working when I user .json()
.get() is Working
<#assign search_query = http.request.parameters.name.get("search_query","optimizely") /> <#assign response = http.client.request("http://community/collection1/select?q=${search_query}&wt=json&indent=true").get() /> <#if response.hasError> ${response.error.message} <#else> ${response.content} </#if>
.json() is NOT Working
<#assign search_query = http.request.parameters.name.get("search_query","optimizely") /> <#assign response = http.client.request("http://community/collection1/select?q=${search_query}&wt=json&indent=true").json() /> <#if response.hasError> ${response.error.message} <#else> ${response.content} </#if>
Error is as below:
{ "error":" FreeMarker template error: The following has evaluated to null or missing: ==> response.hasError [in template "zendesksearchapiurl.ftl" at line 4, column 6] Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)?? The failing instruction (FTL stack trace): ---------- ==> #if response.hasError [in template "zendesksearchapiurl.ftl" at line 4, column 1] ----------
NicoB
11 years agoLithium Alumni (Retired)
Hi Gursimrat
the right call should be
<#assign response = http.client.request("http://community/collection1/select?q=${search_query}&wt=json&indent=true").json().get()
Thanks,
Nico
- NicoB11 years agoLithium Alumni (Retired)Hi Gursimrat,
just to clean up any ambiguity:
1. Is http.client enabled on your instance?
2. Is the URL you're trying to invoke whitelisted in the http client admin screen ?
Related Content
- 10 years ago
- 6 years ago