4
votes

I'm trying to access an API using Postman to get a response using basic authentication, but when I submit the data, it gives me the dreaded 400 error, which apparently indicates that some headers aren't set up properly.

Here's the API info:

Request

Endpoint: {loginUrl}
Data to submit: an email and a password
POST /login HTTP/1.1
Host: {baseUrl}
Accept: application/json
Content-Type: application/json
Content-Length: 68

{
    "email": "{email}",
    "password": "{password}"
}

And in response, I should get an encrypted token in form of JSON, instead I'm getting this error.

Here are the postman screenshots:

Postman_01

Postman_02

Am I missing something?

2
What does the request body look like? What are you posting? What does it expect? Do you have the Auth header set and you’re posting the username and password? Rather than explaining what’s in Postman, might be worth just posting an image of the set up. - Danny Dainton
Is there a reason why you’re sending the Content-Length header in the request? - Danny Dainton
Here are the screenshots from Postman i.imgur.com/lLnbSJ4.jpg i.imgur.com/Ox2eOIm.jpg This is an assignment and I'm still new to REST, all the info I've been given is already covered up there. One of the headers specified was Content-Length in the API docs, so I guess that's why I put it there. - Derrick
I would suggest that you update the question with those images and not add them into the comments. Then you can reformat the wording. - Danny Dainton
Ok, I guess this will make it easier to read. Any suggestions regarding the problem itself? - Derrick

2 Answers

2
votes

From the lack of details it's difficult to offer a specific answer but I can offer something that you can try - The Request data you posted in the question looks like you should be adding:

{
    "email": "{email}",
    "password": "{password}"
}

In the Body section of the request but your images don't show that you've added that to the Body on any request, you've added it as a Auth header instead, so remove that before trying again. I'm not sure of the need to add the Content-Length header as that will change for different username and password combinations in the payload or for the length of the response.

1
votes

I also faced the same issue and i updated my postman header with the below image. Ans issue solved. enter image description here