Forum Discussion
Hm, this code is written as an endpoint. A custom component was written for us to process the data generated by the endpoint.
How can I make the same request in the component?
I tried adding this to the component:
<#assign base = "https://domain.zendesk.com/api/v2/"/>
<#assign url_getUser = base + "users?" + "query=email@domain.com" />
<#assign response_user_no_json = http.client.request(url_getUser).header("Authorization", "Bearer "+ token).get() />
${response_user_no_json}
and receive
FreeMarker template error
get(client) failed on instance of lithium.coreapi.webui.template.models.HttpTemplateModel. See cause exception. The failing instruction (FTL stack trace): ---------- ==> #assign response_user_no_json = http... [in template "preview" at line 28, column 29] ----------
If I try removing the client:
<#assign response_user_no_json = http.request(url_getUser).header("Authorization", "Bearer "+ token).get() />
I get :
FreeMarker template error
For "...(...)" callee: Expected a method, but this evaluated to an extended_hash+string (lithium.coreapi.webui.template.models.RequestTemplateModel wrapped into f.e.b.StringModel): ==> http.request [in template "preview" at line 28, column 62] The failing instruction (FTL stack trace): ---------- ==> #assign response_user_no_json = http... [in template "preview" at line 28, column 29] ----------
Any help you can provide here will be very beneficial!
Hey perk,
Sorry for the frustrating debugging. I'm able to reproduce the error in an endpoint as follows (will output ERROR with the error or SUCCESS with the content):
<#assign base = "https://domain.zendesk.com/api/v2/"/> <#assign url_getUser = base + "users?" + "query=email@domain.com"?url('UTF-8') /> <#assign response_user_no_json = http.client.request(url_getUser).get() /> <#if response_user_no_json.hasError> ERROR: ${response_user_no_json.error.message} <#else> SUCCESS: ${response_user_no_json.content} </#if>
In my case I am getting "ERROR: error making http request: Unsupported Media Type" which means that the zendesk service is rejecting the request for some reason.
I think DougS will be able to help you debug this further, but you may also want to check with Zendesk to figure out under what scenarios they send this error back.
Note: http.client only works in endpoints currently, but you can access endpoints directly via url by clicking the "View http Endpoint" button on the Endpoints screen
Hope this helps,
Yuri
Related Content
- 5 years ago
- 5 years ago