apickli - json payload ignoring integers and transforming them to strings

Hello everyone. I'm currently trying to find a solution to this issue I'm having with APICKLI. The problem is very simple. I'm trying to create a test case in which I need to send a JSON payload and validate the output of the API. Im setting the test to something like this.

Given I set body to {"age": 26, "name": "rick"}
And I set Content-Type header to "application/json"
When I POST to /resource
Then response code should be 201
And response body path $.ok should be true

The problem occurs once I run the tests. The integer values stored inside the respective json properties in the payload are all transformed to strings. I have tried creating a file and storing the json payload so I can pipe it to the body of the request but the behaviour is the same.

Given I store the raw value ./test/features/payload.json as path in scenario scope		
And I pipe contents of file `path` to body
And I set Content-Type header to "application/json"
When I POST to /resource
Then response code should be 201
And response body path $.ok should be true

What Apigee is recieving as payload in this specific example is the following:

{
  "age": "26",
  "name": "rick"
}

What Apigee should receive:

{
  "age": 26,
  "name": "rick"
}

If anyone has any idea of the reason behind this behaviour or a way of going around it without having to change APICKLIs code, I would greatly appreciate it. Thanks in advance.

Ricardo.

0 5 336
5 REPLIES 5

HI @Ricardo Santamaria

Looks like its a Apigee Trace bug. I tried the call from POSTMAN and from apickli, the request is going correct but trace is showing them as string. I have opened an internal ticket for the same (b/165421271)

I have tried this and its not a trace bug. If I send the request from POSTMAN its working. When I execute the same request from APICKLI it does not as it changes all properties to strings.

@Ricardo Santamaria

Are you using the Cloud version of Apigee? or OPDK ? If OPDK, which version

As I mentioned, I made the call from apickli and from Postman, trace showed them all as string. I also added a JS policy to print the request.content and it showed the correct payload

{
  "age": 26,
  "name": "rick"
}

Can you share the screenshot of trace or download the trace files and share that with us that has the calls from apickli and postman?

One more - which version of apickli are you using

I have found the error. Apigee is indeed bugged in trace tool. It is showing all values in a payload as strings. The problem was in APICKLI. When I was setting the content type header with double quotes it sent the payload exaclty as I wanted but not in json format, so apigee received it as string.

You have to set the test case like this:

Given I set body to {"age": 26, "name": "rick"}
And I set Content-Type header to application/json
When I POST to /resource
Then response code should be 201
And response body path $.ok should be true