1

My sample JSON file for postman runner:

[ { "name": "runner", "hitler_id": "4006abc", "year": "2017", "boolean": "false", "expected": 717962 } ]

Pre request script:

var member = data.name; var booking = data.boolean; var fyyear = data.year; var sid = data.hitler_id;
console.log(data.name); console.log(data.boolean); console.log(data.year); console.log(data.hitler_id);

Body with parameters:

{ "size": 0, "query": { "bool": { "filter": [ { "terms": { "name": [ "{{name}}" ] } }, { "terms": { "salesman_id": [ "{{sid}}" ] } }, { "terms": { "fyyear": [ "{{fyyear}}" ] } }, { "terms": { "boolean": [ "{{boolean}}" ] } } ] } }, "aggs": { "year": { "terms": { "field": "year" }, "aggs": { "value": { "sum": { "field": "value" } } } } } }

For only string variables are accepted - name and boolean fields are working and the value is populated for the other two, the variable values are not passed.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Venkat
  • 11
  • 2

1 Answers1

0

The variables are not used in your request body that way. Either you have to store them in environment oder global variables via

pm.globals.set("variable_key", variable_value)
pm.environment.set("variable_key", "variable_value");

or just skip the pre-request script if you just want to use your data and reference the fields directly in your body:

{
    "size": 0,
    "query": {
        "bool": {
            "filter": [
                {
                    "terms": {
                        "name": [
                            "{{name}}"
                        ]
                    }
                },
                {
                    "terms": {
                        "salesman_id": [
                            "{{hitler_id}}"
                        ]
                    }
                },
                {
                    "terms": {
                        "fyyear": [
                            {{year}}
                        ]
                    }
                },
                {
                    "terms": {
                        "boolean": [
                            {{boolean}}
                        ]
                    }
                }
            ]
        }
    },
    "aggs": {
        "year": {
            "terms": {
                "field": "year"
            },
            "aggs": {
                "value": {
                    "sum": {
                        "field": "value"
                    }
                }
            }
        }
    }
}

However take care you're storing the values in your data file. You stored the bool and the year as strings". But they should be represented as you already did for the "expected" var.

DieGraueEminenz
  • 830
  • 2
  • 8
  • 18
  • boolean and name data is flowing in. Bt id and year are not flowing in. As id has string and numbers so on or not sure. I am using as data, i hav to test multiple scenario as regression tests for totals. How to pass integer variable, i hav used both "{{year}}" and {{year}} both didn't work out. The issue occurs for integers and integers+string i guess as names and boolean values are taken as string and passed in the body. – Venkat Apr 19 '20 at 07:58
  • You must define them properly in your data file as well. Acutually i see the "year" ist "2017" instead of 2017 and so on – DieGraueEminenz Apr 19 '20 at 16:30