I’m trying to make a POST request and I’ve set the headers for it and the content but it doesn’t get me the right result:
export default async function postNewTopic(req, res) {
axios.post(`url/posts.json?title="${req.query.title}"&raw=${req.query.content}&category=1`, {
headers: {
"Api-Key": token ,
"Api-Username": {My key}
}})
.then(function (response) {
res.json(response.data);
})
.catch(function (error) {
const err = error?.response?.data || error;
res.status(error.status || error.statusCode || +error.code || 500).json(err)
})
}
And here is my frontend code:
const createTopic = () => {
axios.post(`api/post-new?title=${title}&raw=${content}&category=1`, {
headers: {
"Authorization": 'Bearer' + "",
"Api-Key": token ,
"Api-Username": ""
}})
.then(function (response) {
res.json(response.data);
})
.catch(function (error) {
const err = error?.response?.data || error;
console.log(error.response.data)
})
}