UiPath Documentation
functions
latest
false
Functions user guide
  • Overview
    • About Functions
    • Licensing
  • JavaScript functions
    • Getting started
    • Building JavaScript functions
    • HTTP triggers and routing
    • Function context
    • Accessing platform services
    • Testing and debugging
  • Python functions
  • Deploy and run

Getting started

Install the CLI, scaffold a JavaScript or TypeScript function project, and run your first function locally.

This page walks you through installing the CLI, scaffolding a project, and running your first JavaScript function locally.

Prerequisites​

  • Node.js 20 or later.
  • The uip CLI with the functions tool:
npm install -g @uipath/cli
uip tools install @uipath/function-tool
npm install -g @uipath/cli
uip tools install @uipath/function-tool
  • A UiPath account with access to Orchestrator, for publishing and invoking.

Scaffold a project​

uip function new my-functions --kind http
cd my-functions
uip function new my-functions --kind http
cd my-functions

--kind http creates a project of HTTP functions (targetRuntime javascript-server). --kind job, the default, creates a project of job functions (javascript). TypeScript is the default language; pass -l js for JavaScript, or --empty to skip the sample function.

The project contains:

FilePurpose
functions/hello.tsYour function. Each file directly in functions/ is one function.
functions/_*.tsShared helpers. A file whose name starts with an underscore is not a function.
uipath.jsonThe project's targetRuntime and the list of functions. The CLI keeps the list in sync with functions/.
project.uiprojThe project name and its main function.
package.json, package-lock.json, tsconfig.jsonStandard project files.

Write your first function​

import { defineFunction, defineSchema } from "@uipath/coded-functions-js-sdk";

interface HelloInput {
  name: string;
}

interface HelloOutput {
  message: string;
}

export default defineFunction({
  name: "hello",
  method: "POST",
  path: "/hello",
  input: defineSchema<HelloInput>(),
  output: defineSchema<HelloOutput>(),
  handler: async (input) => ({ message: `Hello, ${input.name}!` }),
});
import { defineFunction, defineSchema } from "@uipath/coded-functions-js-sdk";

interface HelloInput {
  name: string;
}

interface HelloOutput {
  message: string;
}

export default defineFunction({
  name: "hello",
  method: "POST",
  path: "/hello",
  input: defineSchema<HelloInput>(),
  output: defineSchema<HelloOutput>(),
  handler: async (input) => ({ message: `Hello, ${input.name}!` }),
});

defineSchema<T>() derives the JSON Schema from your TypeScript interface, so the same type declares the contract and types the handler. In JavaScript projects, pass a JSON Schema object instead.

The method and path make this an HTTP function. A job function declares neither. See Building JavaScript functions.

Run it locally​

uip function serve
uip function serve

This starts a hot-reload server on http://localhost:7070. Call the function:

curl -X POST http://localhost:7070/hello \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice"}'
# {"message":"Hello, Alice!"}
curl -X POST http://localhost:7070/hello \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice"}'
# {"message":"Hello, Alice!"}

To reach Orchestrator from a local run, put UIPATH_ACCESS_TOKEN, UIPATH_BASE_URL, UIPATH_ORG_ID and UIPATH_TENANT_ID in a .env file at the project root. serve loads it.

Next steps​

Was this page helpful?

Connect

Need help? Support(opens in new window)

Want to learn? UiPath Academy(opens in new window)

Have questions? UiPath Forum(opens in new window)

Stay updated