UiPath Documentation
integration-service
2.2510
true
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 Integration Service で提供されるコネクタ パッケージの一部は機械翻訳で処理されています。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。
UiPath logo, featuring letters U and I in white

Integration Service ユーザー ガイド

最終更新日時 2026年4月15日

Global Scripts

The Global Scripts tab in Connector Builder lets you write JavaScript that runs before or after every API request made by your connector. Use pre-request scripts to modify outgoing requests and post-request scripts to process incoming responses.

When to use Global Scripts

Global Scripts are useful when you need to apply consistent logic across all requests in a connector, such as:

  • Injecting or overriding request headers, parameters, or body before sending
  • Dynamically constructing the vendor URL based on configuration values
  • Transforming a vendor response body before it is returned to the workflow
  • Stopping a request based on custom conditions without calling the vendor API

Writing scripts

To open the Global Scripts tab:

  1. In Integration Service, open Connector Builder and select your custom connector.
  2. Select Global Scripts from the top navigation.
  3. Expand Pre-request script or Post-request script and enter your JavaScript.

Scripts run in a sandboxed JavaScript environment. The following constraints apply:

  • require() is available for a pre-approved set of libraries only (see Using Snippets). Arbitrary packages cannot be imported.
  • Network APIs (fetch, XMLHttpRequest, WebSocket) are not available.
  • eval is not available.
  • Standard JavaScript built-ins (JSON, Date, Array, Object, URL, Buffer, encodeURIComponent) are available.

The done() function

Every script must call done() to signal completion. done() terminates execution immediately — any code written after done() is unreachable.

// Pass through unchanged
done();

// Override one or more output values
done({
  request_vendor_headers: updatedHeaders
});

// Return multiple overrides
done({
  request_vendor_body: newBody,
  request_vendor_headers: newHeaders
});

// Stop the request — do not call the vendor API
done({ continue: false });

// Stop the request and return an error
done({
  continue: false,
  response_status_code: 400,
  response_error_message: "Invalid action"
});
// Pass through unchanged
done();

// Override one or more output values
done({
  request_vendor_headers: updatedHeaders
});

// Return multiple overrides
done({
  request_vendor_body: newBody,
  request_vendor_headers: newHeaders
});

// Stop the request — do not call the vendor API
done({ continue: false });

// Stop the request and return an error
done({
  continue: false,
  response_status_code: 400,
  response_error_message: "Invalid action"
});

Using Snippets

Select Snippets in the script panel to insert code templates into the active script editor. The following templates are available:

  • Import a library — Inserts a require() call for one of the pre-approved libraries available in the script sandbox: buffer, crypto, http, https, querystring, url, util, zlib, axios, lodash, jmespath, moment, request, request-promise.
  • Prerequisite scripts:
    • Update a provider — Inserts a template for modifying outgoing vendor request properties.
    • Use a config object — Inserts a template for reading connector configuration values.
    • Stop a provider request — Inserts a done({ continue: false }) pattern to short-circuit the request without calling the vendor API.

Pre-request scripts

A pre-request script runs before each API call is sent to the provider. Variables with Write or Read & Write access can be set via done().

変数アクセス説明
request_method読み取りHTTP method of the API call (GET, POST, etc.).
request_vendor_methodRead & WriteHTTP method that will be passed to the provider.
request_headers読み取りRequest headers passed as part of the API call.
request_vendor_headersRead & WriteHeaders that will be sent to the provider.
request_path読み取りRequest path of the API call.
request_vendor_pathRead & WriteRequest path that will be sent to the provider. If the path starts with http, it is used as the full request URL.
request_path_variables読み取りPath variables extracted from the URL template.
request_parameters読み取りQuery parameters passed as part of the API call.
request_vendor_parametersRead & WriteQuery parameters that will be sent to the provider.
request_body読み取りRequest body passed as part of the API call, as a string.
request_body_raw読み取りRequest body passed as part of the API call, as an unprocessed string.
request_vendor_bodyRead & WriteRequest body that will be sent to the provider. Accepts string, list, or map on write.
request_body_map読み取りRequest body passed as part of the API call, as a map.
request_vendor_body_map読み取りRequest body that will be sent to the provider, as a map.
request_vendor_url読み取りFully formed endpoint URL that will be used for the vendor call.
request_expression読み取りCEQL where parameter converted to a list of {attribute, value, operator} maps.
request_previous_response読み取りResponse body from the previous chained resource. null if not part of a chain.
request_previous_response_headers読み取りResponse headers from the previous chained resource. null if not part of a chain.
request_root_keyRead & WriteDot-notation path to build a sub-object in the request JSON payload (e.g. data.record).
object_name読み取りCanonical object name for the request.
vendor_object_name読み取りVendor object name. Same as object_name unless overridden on the resource.
configuration読み取りConnector configuration properties.
response_status_code書き込みHTTP status code to return when continue is false.
response_error_message書き込みError message to return before the request is sent to the vendor.
response_body書き込みResponse body to return when continue is false.
response_body_raw書き込みResponse body as a string to return when continue is false.
response_root_keyRead & WriteDot-notation path to limit the response to a sub-object (e.g. data.records).
multipart_hook_context_itemsRead & WriteMultipart form items for file upload requests.
continue書き込みSet to false to skip the vendor call. Defaults to true.

Example: Inject a dynamic header from configuration

var headers = request_vendor_headers || {};
var config = configuration || {};

headers['Authorization'] = 'Bearer ' + config['oauth_token'];

done({ request_vendor_headers: headers });
var headers = request_vendor_headers || {};
var config = configuration || {};

headers['Authorization'] = 'Bearer ' + config['oauth_token'];

done({ request_vendor_headers: headers });

Example: Override the vendor URL path

var baseUrl = configuration['base_url'];
if (!baseUrl) {
  done({ continue: false, response_error_message: "Missing configuration: 'base_url'" });
  return;
}

var apiVersion = configuration['api_version'] || 'v1';
var modelId = request_path_variables.modelId;
var vendorUrl = baseUrl.startsWith('http') ? baseUrl : 'https://' + baseUrl;

done({
  request_vendor_path: vendorUrl + '/' + apiVersion + '/models/' + modelId + '/completions'
});
var baseUrl = configuration['base_url'];
if (!baseUrl) {
  done({ continue: false, response_error_message: "Missing configuration: 'base_url'" });
  return;
}

var apiVersion = configuration['api_version'] || 'v1';
var modelId = request_path_variables.modelId;
var vendorUrl = baseUrl.startsWith('http') ? baseUrl : 'https://' + baseUrl;

done({
  request_vendor_path: vendorUrl + '/' + apiVersion + '/models/' + modelId + '/completions'
});

Example: Modify the request body

var body = typeof request_body_map === 'string'
  ? JSON.parse(request_body_map)
  : request_body_map;

body.max_tokens = body.max_tokens || 1024;
body.temperature = 0.7;

done({
  request_vendor_headers: { 'Content-Type': 'application/json' },
  request_vendor_body: JSON.stringify(body)
});
var body = typeof request_body_map === 'string'
  ? JSON.parse(request_body_map)
  : request_body_map;

body.max_tokens = body.max_tokens || 1024;
body.temperature = 0.7;

done({
  request_vendor_headers: { 'Content-Type': 'application/json' },
  request_vendor_body: JSON.stringify(body)
});

Post-request scripts

A post-request script runs after a response is received from the vendor. All pre-request variables remain available as Read. The response-specific variables below are added, and configuration becomes Read & Write. Variables with Write or Read & Write access can be set via done().

変数アクセス説明
response_iserror読み取りtrue if the vendor response indicates an error (status codes outside 200–207).
response_status_codeRead & WriteHTTP status code from the vendor.
response_bodyRead & WriteResponse body from the vendor.
response_body_rawRead & WriteRaw response body from the vendor, as a string.
response_body_raw_map読み取りRaw response body from the vendor, as a map.
response_body_map読み取りResponse body from the vendor, as a map.
response_headersRead & WriteResponse headers from the vendor.
response_error_message書き込みError message to return. Converts the response into an error.
response_root_keyRead & WriteDot-notation path to limit the response to a sub-object (e.g. data.records).
configurationRead & WriteConnector configuration properties. Changes persist to the connector instance.
multipart_hook_context_itemsRead & WriteMultipart form items for file upload requests.
metadata_merge書き込みSet to true to combine vendor metadata with model metadata.
ヒント:

Start every post-request script with an error guard. If the response is an error, call done() with no arguments to pass it through unchanged.

Example: Transform the response body

if (response_iserror) {
  done();
  return;
}

var body = typeof response_body === 'string'
  ? JSON.parse(response_body)
  : response_body;

body.processed = true;
body.timestamp = new Date().toISOString();

done({ response_body: body });
if (response_iserror) {
  done();
  return;
}

var body = typeof response_body === 'string'
  ? JSON.parse(response_body)
  : response_body;

body.processed = true;
body.timestamp = new Date().toISOString();

done({ response_body: body });

Utility functions

The following utility functions are available in both script types:

機能説明
console.log()Outputs a debug message.

Bring your own LLM connector use case

If you are building a connector for an LLM provider — such as a self-hosted model or a third-party inference endpoint — Global Scripts let you adapt requests and responses to match the expected contract without modifying each resource individually.

ヒント:

For common LLM providers (AWS Bedrock, Azure OpenAI, Google Vertex AI, OpenAI V1 Compatible), you can start from a connector template that pre-populates the authentication setup and scripts for you. For details, see Using connector templates.

The following scripts show a complete pre-request and post-request setup for this scenario.

Pre-request: Set authentication headers

Inject the provider's API key from the connector configuration and enforce the expected Content-Type:

var headers = {
  'Content-Type': 'application/json',
  'x-api-key': configuration['api_key']
};

done({
  request_vendor_headers: headers,
  request_vendor_body: request_body_map
});
var headers = {
  'Content-Type': 'application/json',
  'x-api-key': configuration['api_key']
};

done({
  request_vendor_headers: headers,
  request_vendor_body: request_body_map
});

Pre-request: Inject a system message

Set default model parameters and ensure a system message is present in every conversation sent to the model:

var body = typeof request_body_map === 'string'
  ? JSON.parse(request_body_map)
  : request_body_map;

body.max_tokens = body.max_tokens || 1024;
body.temperature = 0.7;

var hasSystemMessage = body.messages.some(function(msg) {
  return msg.role === 'system';
});

if (!hasSystemMessage) {
  body.messages.unshift({
    role: 'system',
    content: 'You are a helpful assistant.'
  });
}

done({
  request_vendor_headers: { 'Content-Type': 'application/json' },
  request_vendor_body: JSON.stringify(body)
});
var body = typeof request_body_map === 'string'
  ? JSON.parse(request_body_map)
  : request_body_map;

body.max_tokens = body.max_tokens || 1024;
body.temperature = 0.7;

var hasSystemMessage = body.messages.some(function(msg) {
  return msg.role === 'system';
});

if (!hasSystemMessage) {
  body.messages.unshift({
    role: 'system',
    content: 'You are a helpful assistant.'
  });
}

done({
  request_vendor_headers: { 'Content-Type': 'application/json' },
  request_vendor_body: JSON.stringify(body)
});

Post-request: Process the choices array

Iterate the choices array in the vendor response and add custom metadata before returning to the workflow:

if (response_iserror) {
  done();
  return;
}

var body = typeof response_body === 'string'
  ? JSON.parse(response_body)
  : response_body;

if (body.choices && body.choices.length > 0) {
  body.choices.forEach(function(choice) {
    choice.processed_by = 'connector-post-script';
  });
}

body.custom_metadata = {
  processed: true,
  timestamp: new Date().toISOString()
};

done({ response_body: body });
if (response_iserror) {
  done();
  return;
}

var body = typeof response_body === 'string'
  ? JSON.parse(response_body)
  : response_body;

if (body.choices && body.choices.length > 0) {
  body.choices.forEach(function(choice) {
    choice.processed_by = 'connector-post-script';
  });
}

body.custom_metadata = {
  processed: true,
  timestamp: new Date().toISOString()
};

done({ response_body: body });

ベスト プラクティス

  • Always call done() — a script that does not call done() hangs the request.
  • Copy variables before mutating — the runtime uses strict mode. Assign to a local variable first: var headers = request_vendor_headers;, then modify headers.
  • Do not write code after done() — it is unreachable.
  • Check for null or undefinedrequest_body and request_vendor_body are undefined for GET and DELETE requests.
  • Use continue: false to short-circuit — return a response directly without calling the vendor.

このページは役に立ちましたか?

接続

ヘルプ リソース サポート

学習する UiPath アカデミー

質問する UiPath フォーラム

最新情報を取得