Why am i getting the location when a variable is set to response.content in javascript ? . Can any one help in this

This is how I assigned

context.setVariable("response.content", response);

but in the trace session i could fine response.content =""org.mozilla.javascript.Undefined@*******:

Solved Solved
0 8 1,056
1 ACCEPTED SOLUTION

@surekapoppy@gmail.com ,

Multiple issues found in your proxy ,

  • You have attached Javascript Proxy to Request Pipeline & trying to modify variable "response.content" which scope is Response Pipeline only. Find more about same in Apigee Docs here.
  • You have the following piece of code in your javascript which actually assigns empty variable,
var result;              
context.setVariable("result",JSON.stringify(employees));
context.setVariable("response.content", result);

Above code actually assign empty variable "result" to "response.content"

It should be,

context.setVariable("result",JSON.stringify(employees));
context.setVariable("response.content", context.getVariable("result"));

Find more about same in docs here,

  • See the proxy that works with your use case attached below,

respcontent-rev2-2016-06-21.zip

Sample API call,

curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: c693e22c-d223-093a-0031-13f792caf87d" -d '{"accountingFrom": [ { "firstNameFrom" : "Johnny", "lastNameFrom" : "Doe", "ageFrom" : 23 }, { "firstNameFrom" : "Mary", "lastNameFrom" : "Smith", "ageFrom" : 32 } ] }' "http://anildevportal-test.apigee.net/sample"

Hope it helps, Keep us posted moving forward if any query regarding Apigee.

View solution in original post

8 REPLIES 8

This is how I assigned

context.setVariable("response.content", response);

but in the trace session i could fine response.content =""org.mozilla.javascript.Undefined@*******:

@surekapoppy@gmail.com , Welcome to Apigee Communty.

Can you please provide more details to better understand your issue ? What is your Proxy Doing ? What is code you have used in Javascript ? What do you mean by "location" ? Above question in current form is difficult to answer. Please update your question with more details

@surekapoppy@gmail.com , Flow variable response.content is available out of the box ? Why are you resetting it with response object ? Above issue is expected when you do that. Am i missing something here ?

@surekapoppy@gmail.com , Can you attach a sample proxy to reproduce your issue ?

apiproxy.zip

Please find the sample proxy attached

@surekapoppy@gmail.com , Can you also post sample request you are sending ?

{"accountingFrom": [ { "firstNameFrom" : "Johnny", "lastNameFrom" : "Doe", "ageFrom" : 23 }, { "firstNameFrom" : "Mary", "lastNameFrom" : "Smith", "ageFrom" : 32 } ] }

@surekapoppy@gmail.com ,

Multiple issues found in your proxy ,

  • You have attached Javascript Proxy to Request Pipeline & trying to modify variable "response.content" which scope is Response Pipeline only. Find more about same in Apigee Docs here.
  • You have the following piece of code in your javascript which actually assigns empty variable,
var result;              
context.setVariable("result",JSON.stringify(employees));
context.setVariable("response.content", result);

Above code actually assign empty variable "result" to "response.content"

It should be,

context.setVariable("result",JSON.stringify(employees));
context.setVariable("response.content", context.getVariable("result"));

Find more about same in docs here,

  • See the proxy that works with your use case attached below,

respcontent-rev2-2016-06-21.zip

Sample API call,

curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: c693e22c-d223-093a-0031-13f792caf87d" -d '{"accountingFrom": [ { "firstNameFrom" : "Johnny", "lastNameFrom" : "Doe", "ageFrom" : 23 }, { "firstNameFrom" : "Mary", "lastNameFrom" : "Smith", "ageFrom" : 32 } ] }' "http://anildevportal-test.apigee.net/sample"

Hope it helps, Keep us posted moving forward if any query regarding Apigee.