//native
/**
* Get Token Info
* Return the account (hub ID), user and scopes behind the connected token. Works for private app / service key tokens and for OAuth access tokens.
*/
export async function main(auth: RT.Hubspot) {
// Private app and service key tokens (pat-...) use their own introspection endpoint.
const response = auth.token.startsWith("pat-")
? await fetch(
"https://api.hubapi.com/oauth/v2/private-apps/get/access-token-info",
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ tokenKey: auth.token }),
}
)
: await fetch(
`https://api.hubapi.com/oauth/v1/access-tokens/${auth.token}`,
{ headers: { Accept: "application/json" } }
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 hours ago