//native
type Brex = {
token: string;
};
/**
*
Invite user
*
This endpoint invites a new user as an employee.
To update user's role, check out [this article](https://support.brex.com/how-do-i-change-another-user-s-role/).
*/
export async function main(
auth: Brex,
body: {
first_name: string;
last_name: string;
email: string;
manager_id?: string;
department_id?: string;
location_id?: string;
title_id?: string;
metadata?: {};
},
Idempotency_Key?: string,
) {
const url = new URL(`https://platform.brexapis.com/v2/users`);
const response = await fetch(url, {
method: "POST",
headers: {
...(Idempotency_Key ? { "Idempotency-Key": Idempotency_Key } : {}),
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 217 days ago