Assign message policy not reading json variable properly

Not applicable

jsontestassignmessage-rev1-2016-03-21.zipI have Assign message policy which reads a header variable.The header variable is populated with json message.

While reading that header variable,Assign message policy is not reading once it encounters comma in the json message.How to solve this issue?

For this input below,

{ "Fruits": [ { "Name": "Apple",Count": "20"}, { "Name": "Mango",Count": "30"}] }

Assign message policy:

<AssignVariable> <Name>Fruit</Name> <Value/> <Ref>request.header.Fruit</Ref> </AssignVariable>

Output variable "Fruit":

{ "Fruits": [ { "Name": "Apple"

But when I provide input as,

{ "Name": "Apple"}

Output variable "Fruit":

{ "Name": "Apple"}

I have also attached the Proxy bundle.

Solved Solved
0 3 195
1 ACCEPTED SOLUTION

Generally if you provide value as a comma separated for HTTP header it means that you are providing array of a header .

so for example :

Cache-Control: no-cache, no-store

is equivalent to (order is important)

Cache-Control: no-cache

Cache-Control: no-store

Thus when you read the variable in apigee, it reads the part till comma.

View solution in original post

3 REPLIES 3

To resolve that problem, I would suggest either:

  1. pass the JSON as payload body
  2. encode the JSON before use, and decode it in the proxy
  3. use the form "request.header.Fruit.values"

Read about the last, here:

http://docs.apigee.com/api-services/reference/variables-reference

BUT, I don't understand why you would simply assign the value of one variable to another.

Why not just use the first variable?

Thankyou @Dino

This I am doing this for a usecase here.

Generally if you provide value as a comma separated for HTTP header it means that you are providing array of a header .

so for example :

Cache-Control: no-cache, no-store

is equivalent to (order is important)

Cache-Control: no-cache

Cache-Control: no-store

Thus when you read the variable in apigee, it reads the part till comma.