Diffrence in Two API response

Hi Postman Community I want to automate to see two api response diffrences.
Like in First API response

[
    {
        color: "red",
        value: "#f00"
    },
    {
        color: "green",
        value: "#0f0"
    }
]

2nd API Response

[
    {
        color: "red",
        value: "#f00"
    },
    {
        color: "green",
        value: "#0f2"
    }
]

I want to get info in run results like:

in first response there was value: “#0f0” and in second there is value: “#0f2

Hey @security-administr11 :wave:

Welcome to the Postman community! :postman:

What have you tried so far? Have you done any research around storing a response as a variable and asserting against that data?

This is a common question that has been asked and answered on the forum a number of times already.

Doing some searches on the forum to try and find an answer to this question, will be a better overall learning experience, than someone telling you the answer.

The learning center has a number of different pieces information that can help around creating test scripts.

The Postman Answers Public Workspace also has various solutions to forum questions, like this one:

https://www.postman.com/postman/workspace/postman-answers/collection/13455110-7954de36-7b03-4ea6-989b-8f195a7c5db1?action=share&source=copy-link&creator=8213448

I store the response in 1st api using below code.

jsonData = pm.response.json()
console.log(jsonData)

pm.collectionVariables.set("gcv1", JSON.stringify(jsonData))

In 2nd API using the code to compare

 responseV1 =pm.response.json();
responseV2 = pm.collectionVariables.get("gcv1")

pm.test("compare response ", function()
{
    pm.expect(responseV2).to.equal(JSON.stringify(responseV1));
    
}
)

in the report i am getting

compare response | AssertionError: expected '[{"Id":"18851550","Name":"Acceleratio…' to equal '[{"Id":"12890094","Name":"ADMIRALTY I…'

But i want to see complete mismatch in response

The assertion is telling you that those 2 values do not match, so doing what it’s supposed to do.

If you want to see the mismatches, you’re going to need to expand on the code that you have to display those. Those can only really be exposed in a readable format, on the Postman console.

You could add them to the test name or the assertion error message but depending on the size of the responses, it will start to get messy quite quickly.

What have you searched/researched (either in the forum or google) to see how this can be done?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.