UiPath Documentation
functions
latest
false
Zu den Funktionen im Benutzerhandbuch
  • Überblick
    • Über Funktionen
  • JavaScript functions
    • Erste Schritte
    • Building JavaScript functions
    • HTTP triggers and routing
    • Function context
    • Zugriff auf Plattformdienste
    • Testen und Fehlerbehebung
  • Python-Funktionen
  • Bereitstellen und ausführen
Wichtig :
Dieser Inhalt wurde maschinell übersetzt. Es kann 1–2 Wochen dauern, bis die Lokalisierung neu veröffentlichter Inhalte verfügbar ist.

Function context

The identities, platform coordinates, and request data the runtime passes to every JavaScript function handler.

Every handler receives a context object as its second argument. It carries who called the function, the function's own platform identity, and where to send outbound platform calls — so none of that has to be passed in as input.

handler: async (input, ctx) => {
  ctx.user?.accessToken     // the caller's OAuth token
  ctx.user?.sub             // the caller's user id
  ctx.robot?.accessToken    // the function's own platform token
  ctx.robot?.key            // the serverless robot key
  ctx.platform?.baseUrl     // e.g. "https://cloud.uipath.com"
  ctx.platform?.orgId       // organization id
  ctx.platform?.tenantId    // tenant id
  ctx.platform?.folderKey   // folder of the invocation, if any
  ctx.params                // path parameters, as strings
  ctx.headers               // request headers, lowercase keys
}
handler: async (input, ctx) => {
  ctx.user?.accessToken     // the caller's OAuth token
  ctx.user?.sub             // the caller's user id
  ctx.robot?.accessToken    // the function's own platform token
  ctx.robot?.key            // the serverless robot key
  ctx.platform?.baseUrl     // e.g. "https://cloud.uipath.com"
  ctx.platform?.orgId       // organization id
  ctx.platform?.tenantId    // tenant id
  ctx.platform?.folderKey   // folder of the invocation, if any
  ctx.params                // path parameters, as strings
  ctx.headers               // request headers, lowercase keys
}

Two identities

A function is handed two identities per invocation, and the choice between them is a security decision.

ctx.userctx.robot
Whose it isThe caller who invoked the functionThe function's own platform identity
Permissions that applyThe caller's ownThe function's service account
Use it forActing on behalf of the signed-in userReading resources the caller must not reach directly

ctx.user.accessToken applies when the caller should only see what their own permissions allow. ctx.robot.accessToken applies when the function must reach something the caller cannot — a credential in a restricted folder, for example. See Accessing platform services.

Hinweis:

ctx.robot is the more privileged identity. A handler that reads whatever resource name arrives in the request is acting as a deputy for the caller's request with the function's own privileges. Fetching must be constrained to a fixed set in code.

Platform coordinates

ctx.platform supplies baseUrl, orgId and tenantId for outbound platform calls. These come from the runtime, never from the caller, so a request cannot redirect where the function sends its traffic, and they must never be accepted as input fields.

It is all-or-nothing: ctx.platform is null unless all three are available. folderKey can be null on its own, for a folderless invocation.

What is available where

HTTP triggerAuftragLokal (Local) serve
ctx.userThe caller's identityNo caller identityPresent when the request carries a bearer token
ctx.robotJaJanull
ctx.platformJaJaOnly with UIPATH_BASE_URL, UIPATH_ORG_ID and UIPATH_TENANT_ID set
ctx.params, ctx.headersJaEmpty — there is no HTTP requestJa

Because ctx.robot is null locally, code that needs a platform token should fall back to an environment variable for local development:

const token = ctx.robot?.accessToken || process.env["UIPATH_ACCESS_TOKEN"] || "";
const token = ctx.robot?.accessToken || process.env["UIPATH_ACCESS_TOKEN"] || "";

Nächste Schritte

  • Two identities
  • Platform coordinates
  • What is available where
  • Nächste Schritte

War diese Seite hilfreich?

Verbinden

Benötigen Sie Hilfe? Support

Möchten Sie lernen? UiPath Academy

Haben Sie Fragen? UiPath-Forum

Auf dem neuesten Stand bleiben