'Somebody knows how to solve 401 Unauthorized error with Clockify API using axios and node js
Does someone know why I'm getting a 401 Unauthorized error when I try to post a request to add a time entry even though I have added my API key?
I'm using Axios and node js, and this is the information and how I am making the request. However, I am able to get a list of users using the axios.get() method with the same API key, so I'm not sure why the post request says I'm not Unauthorized.
const insertOwnTimeEntryUrl = `${url}/workspaces/${workspaceId}/time-entries`;
let payload = {
start: "2022-05-05T17:10:00.000Z",
billable: "true",
description: "Test insert 1",
projectId: projectIdToInsert,
taskId: taskIdToInsert,
end: "",
tagIds: [tagIdToInsert],
};
let headers = {
"X-Api-Key": key,
};
let clockifyData = {
headers,
payload,
};
async function addNewEntry(clockifyData, insertOwnTimeEntryUrl, key) {
return (response = await axios
.post(`${insertOwnTimeEntryUrl}`, {
data: clockifyData.payload,
headers: {
"X-Api-Key": key,
"Content-Type": "application/json",
},
})
.catch(function (error) {
console.log(error.response.data.message);
return;
}));
}
addNewEntry(clockifyData, insertOwnTimeEntryUrl, key);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|