//native
type Clickup = {
token: string;
};
/**
* Get Access Token
* These are the routes for authing the API and going through the [OAuth flow](doc:authentication).\
\
Applications utilizing a personal API token don't use this endpoint.\
\
***Note:** OAuth tokens are not supported when using the [**Try It** feature](doc:trytheapi) of our Reference docs. You can't try this endpoint from your web browser.*
*/
export async function main(
auth: Clickup,
client_id: string | undefined,
client_secret: string | undefined,
code: string | undefined,
) {
const url = new URL(`https://api.clickup.com/api/v2/oauth/token`);
for (const [k, v] of [
["client_id", client_id],
["client_secret", client_secret],
["code", code],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 168 days ago