type Asana = {
token: string;
};
/**
* Add users to a project
* Adds the specified list of users as members of the project. Note that a user being added as a member may also be added as a *follower* as a result of this operation. This is because the user's default notification settings (i.e., in the "Notifcations" tab of "My Profile Settings") will override this endpoint's default behavior of setting "Tasks added" notifications to `false`.
Returns the updated project record.
*/
export async function main(
auth: Asana,
project_gid: string,
opt_pretty: string | undefined,
opt_fields: string | undefined,
body: {
data?: { members: string; [k: string]: unknown };
[k: string]: unknown;
}
) {
const url = new URL(
`https://app.asana.com/api/1.0/projects/${project_gid}/addMembers`
);
for (const [k, v] of [
["opt_pretty", opt_pretty],
["opt_fields", opt_fields],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"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 418 days ago