cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with webscript response template

abraxas
Champ in-the-making
Champ in-the-making
Hello,

I'm trying to write some simple webscripts but when I try to use response templates to return some data
I get a template exception : 05200035 Error during processing of the template Expression "expression" is undefined on line …

For example:
test.post.json.js

function main(){
model.test = "Hello!";
}
main();
test.post.json.ftl
{
"test" : "${test}"
}
test.post.desc.xml
<webscript>
  <shortname>test</shortname>
  <description>test</description>
  <url>/api/test/</url>
  <format default="json">argument</format>
  <authentication>user</authentication>
  <transaction allow="readwrite">required</transaction>
</webscript>

Returns a TemplateException: 05200036 Error during processing of the template 'Expression test is undefined on line 2
in the log.

I'm calling my scripts using cURL,
curl -uadmin:admin -d  "" http://www.alfresco.test/alfresco/s/api/test/
2 REPLIES 2

mikeh
Star Contributor
Star Contributor
You've specified the JavaScript controller as ".post.json.js" but this controller will only be used if the request content type is JSON.

i.e you need to add the ""Content-Type: application/json" header to your request.

In general, it's good practice in Freemarker templates to handle potentially missing variables, i.e.
${test!""}

Thanks,
Mike

abraxas
Champ in-the-making
Champ in-the-making
Thank you Mike,
setting the header solved it. I somehow totally forgot about that  Smiley Surprisedops: