diff --git a/components/servicenow/actions/get-current-user/get-current-user.mjs b/components/servicenow/actions/get-current-user/get-current-user.mjs index 7eef885e3b473..91cbb0edd020f 100644 --- a/components/servicenow/actions/get-current-user/get-current-user.mjs +++ b/components/servicenow/actions/get-current-user/get-current-user.mjs @@ -1,11 +1,10 @@ -import { axios } from "@pipedream/platform"; import servicenow from "../../servicenow.app.mjs"; export default { key: "servicenow-get-current-user", name: "Get Current User", description: "Returns the authenticated ServiceNow user's sys_id, name, email, username, and instance URL. Call this first when the user says 'my incidents', 'my cases', 'assigned to me', or needs their ServiceNow identity. Use `sys_id` to filter records in **Get Table Records** (e.g. `assigned_to={sys_id}`) or **Create Table Record**. [See the documentation](https://docs.servicenow.com/bundle/vancouver-api-reference/page/integrate/inbound-rest/concept/c_TableAPI.html).", - version: "0.0.1", + version: "0.0.2", type: "action", annotations: { destructiveHint: false, @@ -16,31 +15,30 @@ export default { servicenow, }, async run({ $ }) { - const sessionInfo = await axios($, { - url: `${this.servicenow.baseUrl()}/api/now/ui/user/current_user`, - headers: this.servicenow.authHeaders(), + const sessionInfo = await this.servicenow._makeRequest({ + $, + url: "/ui/user/current_user", }); - const userSysId = sessionInfo.result?.user_sys_id; + const userSysId = sessionInfo?.sys_id; if (!userSysId) { throw new Error("Unable to determine current user from session"); } - const userResponse = await axios($, { - url: `${this.servicenow.baseUrl()}/api/now/table/sys_user/${userSysId}`, - headers: this.servicenow.authHeaders(), + const user = await this.servicenow._makeRequest({ + $, + url: `/table/sys_user/${userSysId}`, params: { sysparm_fields: "sys_id,user_name,name,email,title,department,location", }, }); - const user = userResponse.result; const summaryName = user.name || user.user_name || user.sys_id; $.export("$summary", `Retrieved user ${summaryName}`); return { - instance_url: this.servicenow.baseUrl(), + instance_url: `https://${this.servicenow.$auth.instance_name}.service-now.com`, sys_id: user.sys_id, user_name: user.user_name, name: user.name, diff --git a/components/servicenow/package.json b/components/servicenow/package.json index d7c563af8dc43..6fc849bbc518c 100644 --- a/components/servicenow/package.json +++ b/components/servicenow/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/servicenow", - "version": "0.10.1", + "version": "0.10.2", "description": "Pipedream ServiceNow Components", "main": "servicenow.app.mjs", "keywords": [