Edits history of script submission #22320 for ' Get User Info (salesforce)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get User Info
     * Return the authenticated user's identity (user_id, email, organization_id, username). user_id is the OwnerId for "my records" SOQL filters.
     */
    export async function main(auth: RT.Salesforce) {
      const url = new URL(`${auth.instance_url}/services/oauth2/userinfo`)
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 9 days ago