ipadtool/mosyle.js
2025-06-09 13:32:53 -04:00

25 lines
674 B
JavaScript

export function call(endpoint, data, auth) {
const headers = {
"Content-Type": "application/json",
};
if (auth) headers.Authorization = `Bearer ${auth}`;
return fetch("https://managerapi.mosyle.com/v2" + endpoint, {
method: "POST",
headers,
body: JSON.stringify(data),
});
}
export async function authenticate(email, password, token) {
const response = await call("/login", {
email,
password,
accessToken: token,
});
if (!response.ok) throw new Error("Authentication failed");
return response.headers.get("Authorization").replace(/^Bearer\s/, "");
}
export function bulk(data, auth) {
return call("/bulkops", data, auth);
}