useMutation POST request returning `(400) Bad Request`
I created and tested an API for multipart/form data POST request using ExpressJs and Postman(for testing). Everything works fine in postman but trying make the request on client-side(React) using useMutation is returning the `(400) Bad Request.
Below is the code
For API controller file
Client-side(React) code
Help will be appreciated
7 Replies
manual-pink•4y ago
How do you know it's returning the 400? It doesn't look like you're using the data from the mutation for anything
or
fascinating-indigoOP•4y ago
Thanks for your response.
It returns the error whenever I click the submit button. This is my first time using useMutation and I followed the documentation and some tutorial. I assumed the
data is already returned by the postBlog() and that the POST query will be invoked by mutate().manual-pink•4y ago
Yeah, the response from postBlog would end up in the onSuccess callback as the first argument (unless the request has a non-200 then Axios will throw which will be caught by react-query and it'll instead call the onError callback). I still don't know what you mean by "it returns the error" though.
fascinating-indigoOP•4y ago
This is the response I get whenever I click the submit button

fascinating-indigoOP•4y ago
I believe
onSuccess() will only return something if the query is successful which it isn't.manual-pink•4y ago
Doesn't look like the problem is related to react query, looks like your request is invalid. If you called that request without react query it looks like it would still fail with the same error
fascinating-indigoOP•4y ago
Yes.
But the request works on Postman.