habitica-sync/view/habiticaAPI.ts

29 lines
964 B
TypeScript
Raw Normal View History

2021-10-08 10:23:06 +05:30
// import fetch from "node-fetch";
2021-10-15 09:41:43 +05:30
export async function getStats(username: string, credentials: string){
const url = "https://habitica.com/export/userdata.json"
2021-10-08 10:23:06 +05:30
const response = fetch(url, {
method: 'GET',
headers: {
"Content-Type": "application/json",
"x-client": username.concat("-testAPI"),
"x-api-user": username,
"x-api-key": credentials,
},
})
return (response)
}
2021-10-15 09:41:43 +05:30
export async function scoreTask(username: string, credentials: string, taskID: string, direction: string) {
const url = "https://habitica.com/api/v3/tasks/".concat(taskID).concat("/score/").concat(direction)
const response = fetch(url, {
2021-10-15 09:41:43 +05:30
method: 'POST',
headers: {
"Content-Type": "application/json",
"x-client": username.concat("-testAPI"),
"x-api-user": username,
"x-api-key": credentials,
2021-10-15 09:41:43 +05:30
}
})
2021-10-15 09:41:43 +05:30
return(response)
}