1

I might not even be using the proper terminology, so I apologize in advance.

I am using Postman to run API calls to collect data for clients and my own research and I need to filter the request by a "sub object" (again not sure about the terminology)

This is the call I used to get the below response:

https://apicfa.convirza.com/v2/call/dni?filter=group_id=8361&limit=10


{
    "result": "success",
    "err": null,
    "data": [
        {
            "call_id": "6834916",
            "call_flow_id": 22830,
            "group_id": 8361,
            "disposition": "ANSWERED",
            "duration": 27,
            "caller_id": "5551234545",
            "tracking_number": "5551234545",
            "ring_to": "5551234545",
            "repeat_call": false,
            "call_started": "2018-05-03T21:30:35.000Z",
            "dni_data": {
                "browser": "Chrome/(Android; Android 7.1.1)",
                "created_at": "2018-05-03T21:30:10.000Z",
                "custom_params": {},
                "destination_url": "",
                "dni_vid": "",
                "first_page": "",
                "ga_cid": "",
                "ip_host": "",
                "last_page": "",
                "log_date": "2018-05-03 21:30:10 UTC",
                "location_details": {

                },
                "ref_param": {
                    "utm_medium": "cpc",
                    "utm_campaign": "GT:Tampa",
                    "utm_source": "google"
                },
                "master_node_id": 8361,
                "organizational_unit_id": 8361,
                "referring": "https://google.com",
                "referring_type": "Paid",
                "referring_url": "",
                "search_words": "Not Provided",
                "session_id": "",
                "updated_at": "",
                "gclid": "EwE",
                "gclsrc": "",
                "phone_numbers": {
                    "id": 60270626,
                    "dni_log_id": "5aeb7f628a95c63fe500055b",
                    "dni_id": "3798",
                    "phone_number": "5551234545",
                    "element": "cfa_eps",
                    "phone_number_id": "",
                    "pool_id": "6118",
                    "number_last_used": "2018-05-03 21:30:10 UTC",
                    "provisioned_route_id": "22830"
                }
            }
        },

What I would like to do is filter by "custom_params" or "utm_medium" but I can not fiqure out how to get to that level. Any help would be greatly appretiated.

2
  • What do you mean by filtering it? Do you want to check a specific value in a test? Commented May 4, 2018 at 6:05
  • Danny, I use Postman to extract data from call records and not as a developer. My goal is to get results like above, extract it, convert it to csv and then present the data to clients. So when I say filter I would like to return all call detail records that meet a specific criteria i.e calls from Google paid... Commented May 4, 2018 at 13:58

2 Answers 2

2

You can try as following;

var responsedata = pm.response.json();

if(responsedata.length > 0) {
    responsedata.data.forEach(function(data) {
        var dniData = data.dni_data
        var customParams = dniData.custom_params
        pm.test("customParams not empty", function () {
            pm.expect(customParams).to.not.equal(null);
        });
        pm.environment.set("customParams", customParams);

        var refParams = dniData.ref_param
        pm.test("refParams not empty", function () {
            pm.expect(refParams).to.not.equal(null);
        });

        var utmMedium = refParams.utm_medium
        pm.test("utmMedium not empty", function () {
            pm.expect(utmMedium).to.not.equal("");
        });
        pm.environment.set("refParams", refParams);
    });
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is using a mixture of old and new Postman syntax, I would recommend editing this to use the newer stuff. You don’t need to JSON.parse the responseBody anymore as pm.response.json() does this. tests[] has been replaced by the pm.test() function.
1

I know that it is a late response, but it can help other people.
Using "JsonPath" this maybe be a solution.

For custom_params use this:
$.data[*].dni_data.custom_params

And, for utm_medium, use this:
$.data[*].dni_data.ref_param.utm_medium

I hope to help the new viewers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.