const getSchool = async () => {
const payload = {
register: "1110000000000",
id_tingkat_kelas: 11,
list_id_produk: [
1, 2, 3, 4, 5, 6, 7,8,9,10, 11, 13, 14, 15, 16
]
};
api.get(`${process.env.NEXT_PUBLIC_API_URL_ORIGIN}/mobile/v18/tobk/ujian-sekolah/all`,
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": `${process.env.NEXT_PUBLIC_API_KEY}`,
Authorization: "Bearer " + session?.user?.token,
},
data: payload
}
)
.then((res) => {
setDataLaporan(res?.data?.data);
setIsLoading(false);
})
.catch((err) => { });
};
Can someone help me?
2
Answers
In Axios, the GET method doesn’t have a data option in its config object. Instead, you can use the params option to send data in the request body while making a GET request.
in axios the GET method does not send a body with the request . you usually send the parameters in the url , however you can change the data option to params . so your code will be like this :
};
you can also switch to another HTTP method like POST to be able to send body in your request