UiPath Documentation
functions
latest
false
Guia do usuário de funções
  • Visão geral
    • Sobre funções
  • JavaScript functions
    • Introdução
    • Building JavaScript functions
    • HTTP triggers and routing
    • Function context
    • Acessando serviços de plataforma
    • Teste e depuração
  • Funções do Python
  • Implantar e executar
Importante :
Este conteúdo foi traduzido com auxílio de tradução automática. A localização de um conteúdo recém-publicado pode levar de 1 a 2 semanas para ficar disponível.

Introdução

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.

Pré-requisitos

  • 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.

Estruturar um projeto

uip function new my-functions -l ts
cd my-functions
uip function new my-functions -l ts
cd my-functions

TypeScript is the default; pass -l js for JavaScript, or --empty to skip the sample function.

The scaffold creates:

de transaçõesFinalidade
functions/hello.tsYour function logic — one function per file. Starts as a runnable example.
functions/_*.tsShared helpers. A leading underscore marks a file as a helper, so it gets no entry point and no trigger.
uipath.jsonMaps function names to their entry points.
package.json, tsconfig.jsonStandard project files.

Escreva sua primeira função

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 function callable over HTTP. Omit both and it runs only as a job — see Building JavaScript functions.

Executar localmente

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 on both supported runtimes.

Próximas Etapas

Esta página foi útil?

Conectar

Precisa de ajuda? Suporte

Quer aprender? Academia UiPath

Tem perguntas? Fórum do UiPath

Fique por dentro das novidades