as you can see in the console, the value of the “data” field is not JSON but a String!
However, the 8th assertion in the submit collection API is checking for this particular string “pm.response.json” in the test script of the “echo the user” API, otherwise, I could just use the pm.repsonse.text() method instead.
After doing some research on the internet and ask the chat GPT, I’m not entirely sure if the failure of the 8th assertion is the wrong formatted json body or not. So, please feel free to share your insights :v
P/s: I think this issue has just occurred recently. I vividly remembered the response body of the echo API was neat and tidy when I did the day 5 challenge
This is using Postman echo, and it should be returning an object, not a string.
What does your body look like as Postman echo just echo’s the body back under the data element.
I get this from time to time when using Postman Echo, where the body looks fine but it keeps returning a string.
Sometimes I have to paste the body into notepad to remove any potential extra formatting, and then paste it back in which can fix the issue. Make sure all of the quotes are normal double quotes, etc as that can also affect it.
For this particular challenge, the variables in the body need to be within quotes like following.
I don’t have any problems with the challenge, the problem is lying within the test script of the submit collection API. For some reasons, the “event” variable of the below block of code is undefined. I wonder if the reason is due to the incorrect formatted of the echo API’s response body
pm.test(“Echo test added”, () => {
let echoRequest = folder.item.find(req => { return req.name === “echo the user”})
console.log(echoRequest)
console.log(echoRequest.event)
let event = echoRequest.event.find(e => {return e.listen === “test”})
pm.expect(event.script.exec.toString(), ‘check parse object’).contains(“pm.response.json”)
pass += 1
})
First of all, this should be its own question. Rather than hi-jacking someone else’s question (which is not related apart from its the same challenge).
I can only recommend to re-read the instructions. These challenges aren’t meant to catch you out, and telling you the answers defeats the main purpose of the challenges\training.
Take a step back and think about the error message.
It’s expecting a variable in the GET request called ‘name’.
You are meant to set the collection variables for name, email and UUID from the GET request response as individual elements in the tests tab.
You’ve set an collection variable called ‘userdata’ using the full response which you then pull apart in the pre-request script for the POST request. You don’t need to do this in the pre-request script. Just set the collection variables for the three elements from the GET request.
Dude, after I tried to submit my collection again, for some unknown reasons all of 8 assertions passed !!?
I have not changed anything at all since I posted this topic.
About the response of my “echo the user” API, it’s still the same. The value of “data” is a string with \r\n all over the place
Now when I check the echoRequest and echoRequest.event with console.log, the result of echoRequest.event is no longer undefined which is of course because the test no longer fails
I literally have not changed anything at all and suddenly it works. Still confused as hell.
Anyway, thanks a lot for trying to help me out. Have a nice day.
wow, it takes me a while to realize what you have been trying to tell me to do.
I did missed those quotes in my body. It worked well in the day 5 challenge without the quotes so I did not think twice about it. Btw I actually thought that you were referring to the double curly brackets since quote could be translated to that in my mother tongue. Silly me :v
Now it’s all clear. Thanks a ton, man xD