Developer forum

Forum » Integration » API UserByEmailOrUsername returns 400 for non-existing users

API UserByEmailOrUsername returns 400 for non-existing users

Jelle De Ridder (eWings)
Reply

Hi everyone,

While testing our integration with the UserByEmailOrUsername API, we noticed that a request with a non-existing email returns a 400 Bad Request, even though the query itself is technically valid.

Example:

GET /Admin/Api/UserByEmailOrUsername?userName=testuser@example.com

Response:

{
  "successful": false,
  "message": "Unable to load query parameters for query type: 'UserByEmailOrUsername'"
}

For an existing user, the same request returns 200 OK with the user model.

We would have expected a 200 OK with successful=false instead of a 400.

Is this an intentional design choice? If so, could you clarify the reasoning behind it?

Thanks in advance.

afbeelding.png

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Well, our endpoint is very explicit on sending a 400 return. So it is a design decission made at that point. You could argue that a 200 is also an option.

Given the error message, the 400 return type is probably chosen since that particular return is coming if we end up with a null object. That can happen for 2 reasons - wrong query parameters or no result from that query. So you could say that those 2 scenarios should be separated and 400 is for invalid querystring keys and 200 with successful=false is for querystring values that do not correspond to any result.

This cannot be changed without bumping the version number of the endpoint - but we will keep it in mind.

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> and 200 with successful=false is for querystring values that do not correspond to any result.

Or a 404 NotFound?

Imar

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

404 would be more of the query does not exist... Or if you are asking for one thing, e.g. /product/{id} and that does not exist. But queries are a mix of searches after one item or a list of items. So 404 or 200 with a no results can both be accepted. And here an object is returned - it is not return with an empty body.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> Or if you are asking for one thing, e.g. /product/{id} and that does not exist

Agreed. Didn't realize this was a broader search, and saw it as /users/{username} which would be a 404.

Imar

 

 

You must be logged in to post in the forum