0

Get User Info

by
Published 8 days ago

Return the authenticated user's identity (user_id, email, organization_id, username). user_id is the OwnerId for "my records" SOQL filters.

Script salesforce Verified

The script

Submitted by hugo989 Bun
Verified 9 days ago
1
//native
2

3
/**
4
 * Get User Info
5
 * Return the authenticated user's identity (user_id, email, organization_id, username). user_id is the OwnerId for "my records" SOQL filters.
6
 */
7
export async function main(auth: RT.Salesforce) {
8
  const url = new URL(`${auth.instance_url}/services/oauth2/userinfo`)
9

10
  const response = await fetch(url, {
11
    method: "GET",
12
    headers: {
13
      Authorization: `Bearer ${auth.token}`,
14
      Accept: "application/json",
15
    },
16
  })
17

18
  if (!response.ok) {
19
    throw new Error(`${response.status} ${await response.text()}`)
20
  }
21

22
  return await response.json()
23
}
24