I am trying to send a post request to my api, however I am getting a 422 response. In insomnia, using the exact same body and everything, I am able to successfully make the request, so I am unsure why my code doesn't do the exact same.
const[stopinfo, setStopInfo] = useState([]);
const requestOptions = {
method: 'POST',
body: JSON.stringify({
'min_date': startDate,
'max_date': endDate,
'min_time': '00:00:00',
'max_time': '23:00:00',
'bus_ids': [2,3,4],
'route_ids': [1,2,3]
})
};
const fetchStopData = async () => {
fetch("https://mywebsite.com/api/data/stopinfo", requestOptions).then(response => response.json())
.then(data => setStopInfo(data))
}
useEffect(() => {
fetchStopData()
},[]);