Getting the 400 error code every time when send the request

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
I am working on the student expert program. I have completed two folder and now trying to do the skill check. I set all requirement as mentioned but when running my test it always gives me 400 bad error.

Details (like screenshots):

How I found the problem:

I’ve already tried:

Hello @BhaveshQA ,

Welcome to the community :partying_face:

Have you added the user-id too? What are you sending as part of your body?

Please try again, and I found a similar topic in the forum.

Hello Pricilla,

I have passed all required parameters. Please check this screenshot

-After send the request it show Respose-value = null

-All Other value I configured properly
-Email
-Auth_key

I am not able to figure out what exactly issue in my sending request.

Regards,
Bhavesh

Helllo Pricilla,

This is my collection link

https://www.getpostman.com/collections/45799079dda9f1480584

Regards,
Bhavesh

Hi @BhaveshQA ,

If possible can you please share the raw request from the console which is sent to the server?

On seeing your collection, it seems the request body doesn’t have JSON selected.

Please check if, under the request header section, Content-Type: application/json is passed…

Hello @pranavdavar

Thanks for reply. I updated to JSON and again run the test.

when print jsondata.rand it gives undefined.

Hello @pranavdavar

This is screenshot for the test tab

Can you please expand the >POST in console and share the screenshot, hiding the sensitive information.

Yes it will give undefined, since you are receiving HTTP 400 i.e. BAD request.

The issue is in request data.

Hi @pranavdavar

Please refer this

The Response-value header is going as null. Please check if the value is populated properly for that header in the variable.

As per previous screenshot, responseData variable is not set and is being used in header.

Hello @pranavdavar

This is code in test tab

var jsonData = JSON.parse(responseBody);

pm.test(“randtesting”, function () {

pm.environment.set(“responseData”, jsonData.rand);

console.log(jsonData.rand)

})

And When I hover mouse on the variable it showing responseData current value = null

The issue is in test script

responseBody is not the variable where Postman stores the response data.

To get response data in JSON you can use the below snippet.
var jsonData=pm.response.json();

Update your script and then try.

var jsonData=pm.response.json();

pm.test(“randtesting”, function () {

pm.environment.set(“responseData”, jsonData.rand);

console.log(jsonData.rand)

})

-Updated script but still same undefined error…

Just now I tested this script. I don’t see any errors. Can you please check now, if the response JSON body contains an element with the “rand” key?

That value should be printed in your console log. Once it is printed. Try sending request again, then you will get 200 as status code.

There is no any key like ‘rand’ in response json

I am confuse now what exactly issue in the request…

rand value will be coming in response. Please check Response body.

@pranavdavar

I run multiple time same request but I only get same error ‘undefined’ and not getting ‘rand’ value in the Response Body.

Is your collection url(as shared earlier) having all the recent changes. I will have a look.

If possible can we connect over screenshare?