I am trying to create post request using formik in reactjs. but it is taking value: in payload thats why 400 error is coming.
const handleSubmit = async (values: any) => {
await axios
.post('http://localhost:3000/api/certificates', {
values,
}).then(function (response) {
console.log(response);
}).catch((err) => {
console.log('error in call');
console.log(err);
});
};
it is generating payload
{
"values": {
"sponser": "Hello",
"startDate": "2021-11-22T13:50:59.073Z",
"endDate": "2021-11-23T13:50:59.000Z",
"phaseOfTrial": "1",
"requestStatus": "DRAFT",
"address": "Hello",
"address2": "Hellpo",
"zipCode": "12345",
"city": "new",
"protoColNo": "12312312",
"molecules": "asdasda",
"unAuthMolecule": "YES",
"noOfSubjects": 5,
"personInCharge": "llasdasdasda",
"country": "asdasdasd",
"comments": "asdasdasdasd",
"attachedFile": "asdasdasd"
}
}
in the payload it is taking values: in the beginning which my API not expecting. what mistake I am doing? how can I remove this?
I think it would work. There is shorthand assignment being done when you do like this {values} => {values: values} Thank you
await axios
.post('http://localhost:3000/api/certificates',values)