@uipath/uipath-typescript 1.3.9 → 1.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1050,14 +1050,25 @@ class ApiClient {
1050
1050
  if (!text) {
1051
1051
  return undefined;
1052
1052
  }
1053
- return JSON.parse(text);
1053
+ try {
1054
+ return JSON.parse(text);
1055
+ }
1056
+ catch (error) {
1057
+ if (error instanceof SyntaxError) {
1058
+ throw new ServerError({
1059
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
1060
+ statusCode: response.status,
1061
+ });
1062
+ }
1063
+ throw error;
1064
+ }
1054
1065
  }
1055
1066
  catch (error) {
1056
1067
  // If it's already one of our errors, re-throw it
1057
1068
  if (error.type && error.type.includes('Error')) {
1058
1069
  throw error;
1059
1070
  }
1060
- // Otherwise, it's likely a network error
1071
+ // Otherwise, it's a genuine network/fetch failure
1061
1072
  throw ErrorFactory.createNetworkError(error);
1062
1073
  }
1063
1074
  }
@@ -1424,9 +1435,9 @@ class PaginationHelpers {
1424
1435
  * @returns Promise resolving to a paginated result
1425
1436
  */
1426
1437
  static async getAllPaginated(params) {
1427
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1438
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1428
1439
  const endpoint = getEndpoint(folderId);
1429
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1440
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1430
1441
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1431
1442
  headers,
1432
1443
  params: additionalParams,
@@ -1454,13 +1465,13 @@ class PaginationHelpers {
1454
1465
  * @returns Promise resolving to an object with data and totalCount
1455
1466
  */
1456
1467
  static async getAllNonPaginated(params) {
1457
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1468
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1458
1469
  // Set default field names
1459
1470
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1460
1471
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1461
1472
  // Determine endpoint and headers based on folderId
1462
1473
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1463
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1474
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1464
1475
  // Make the API call based on method
1465
1476
  let response;
1466
1477
  if (method === HTTP_METHODS.POST) {
@@ -1519,6 +1530,7 @@ class PaginationHelpers {
1519
1530
  serviceAccess: config.serviceAccess,
1520
1531
  getEndpoint: config.getEndpoint,
1521
1532
  folderId,
1533
+ headers: config.headers,
1522
1534
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1523
1535
  additionalParams: prefixedOptions,
1524
1536
  transformFn: config.transformFn,
@@ -1536,6 +1548,7 @@ class PaginationHelpers {
1536
1548
  getAllEndpoint: config.getEndpoint(),
1537
1549
  getByFolderEndpoint: byFolderEndpoint,
1538
1550
  folderId,
1551
+ headers: config.headers,
1539
1552
  additionalParams: prefixedOptions,
1540
1553
  transformFn: config.transformFn,
1541
1554
  method: config.method,
@@ -1048,14 +1048,25 @@ class ApiClient {
1048
1048
  if (!text) {
1049
1049
  return undefined;
1050
1050
  }
1051
- return JSON.parse(text);
1051
+ try {
1052
+ return JSON.parse(text);
1053
+ }
1054
+ catch (error) {
1055
+ if (error instanceof SyntaxError) {
1056
+ throw new ServerError({
1057
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
1058
+ statusCode: response.status,
1059
+ });
1060
+ }
1061
+ throw error;
1062
+ }
1052
1063
  }
1053
1064
  catch (error) {
1054
1065
  // If it's already one of our errors, re-throw it
1055
1066
  if (error.type && error.type.includes('Error')) {
1056
1067
  throw error;
1057
1068
  }
1058
- // Otherwise, it's likely a network error
1069
+ // Otherwise, it's a genuine network/fetch failure
1059
1070
  throw ErrorFactory.createNetworkError(error);
1060
1071
  }
1061
1072
  }
@@ -1422,9 +1433,9 @@ class PaginationHelpers {
1422
1433
  * @returns Promise resolving to a paginated result
1423
1434
  */
1424
1435
  static async getAllPaginated(params) {
1425
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1436
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1426
1437
  const endpoint = getEndpoint(folderId);
1427
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1438
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1428
1439
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1429
1440
  headers,
1430
1441
  params: additionalParams,
@@ -1452,13 +1463,13 @@ class PaginationHelpers {
1452
1463
  * @returns Promise resolving to an object with data and totalCount
1453
1464
  */
1454
1465
  static async getAllNonPaginated(params) {
1455
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1466
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1456
1467
  // Set default field names
1457
1468
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1458
1469
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1459
1470
  // Determine endpoint and headers based on folderId
1460
1471
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1461
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1472
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1462
1473
  // Make the API call based on method
1463
1474
  let response;
1464
1475
  if (method === HTTP_METHODS.POST) {
@@ -1517,6 +1528,7 @@ class PaginationHelpers {
1517
1528
  serviceAccess: config.serviceAccess,
1518
1529
  getEndpoint: config.getEndpoint,
1519
1530
  folderId,
1531
+ headers: config.headers,
1520
1532
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1521
1533
  additionalParams: prefixedOptions,
1522
1534
  transformFn: config.transformFn,
@@ -1534,6 +1546,7 @@ class PaginationHelpers {
1534
1546
  getAllEndpoint: config.getEndpoint(),
1535
1547
  getByFolderEndpoint: byFolderEndpoint,
1536
1548
  folderId,
1549
+ headers: config.headers,
1537
1550
  additionalParams: prefixedOptions,
1538
1551
  transformFn: config.transformFn,
1539
1552
  method: config.method,
@@ -613,14 +613,25 @@ class ApiClient {
613
613
  if (!text) {
614
614
  return undefined;
615
615
  }
616
- return JSON.parse(text);
616
+ try {
617
+ return JSON.parse(text);
618
+ }
619
+ catch (error) {
620
+ if (error instanceof SyntaxError) {
621
+ throw new ServerError({
622
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
623
+ statusCode: response.status,
624
+ });
625
+ }
626
+ throw error;
627
+ }
617
628
  }
618
629
  catch (error) {
619
630
  // If it's already one of our errors, re-throw it
620
631
  if (error.type && error.type.includes('Error')) {
621
632
  throw error;
622
633
  }
623
- // Otherwise, it's likely a network error
634
+ // Otherwise, it's a genuine network/fetch failure
624
635
  throw ErrorFactory.createNetworkError(error);
625
636
  }
626
637
  }
@@ -1284,9 +1295,9 @@ class PaginationHelpers {
1284
1295
  * @returns Promise resolving to a paginated result
1285
1296
  */
1286
1297
  static async getAllPaginated(params) {
1287
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1298
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1288
1299
  const endpoint = getEndpoint(folderId);
1289
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1300
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1290
1301
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1291
1302
  headers,
1292
1303
  params: additionalParams,
@@ -1314,13 +1325,13 @@ class PaginationHelpers {
1314
1325
  * @returns Promise resolving to an object with data and totalCount
1315
1326
  */
1316
1327
  static async getAllNonPaginated(params) {
1317
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1328
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1318
1329
  // Set default field names
1319
1330
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1320
1331
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1321
1332
  // Determine endpoint and headers based on folderId
1322
1333
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1323
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1334
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1324
1335
  // Make the API call based on method
1325
1336
  let response;
1326
1337
  if (method === HTTP_METHODS.POST) {
@@ -1379,6 +1390,7 @@ class PaginationHelpers {
1379
1390
  serviceAccess: config.serviceAccess,
1380
1391
  getEndpoint: config.getEndpoint,
1381
1392
  folderId,
1393
+ headers: config.headers,
1382
1394
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1383
1395
  additionalParams: prefixedOptions,
1384
1396
  transformFn: config.transformFn,
@@ -1396,6 +1408,7 @@ class PaginationHelpers {
1396
1408
  getAllEndpoint: config.getEndpoint(),
1397
1409
  getByFolderEndpoint: byFolderEndpoint,
1398
1410
  folderId,
1411
+ headers: config.headers,
1399
1412
  additionalParams: prefixedOptions,
1400
1413
  transformFn: config.transformFn,
1401
1414
  method: config.method,
@@ -2053,33 +2066,32 @@ class ProcessService extends FolderScopedService {
2053
2066
  }
2054
2067
  }, options);
2055
2068
  }
2056
- /**
2057
- * Starts a process execution (job)
2058
- *
2059
- * @param request - Process start request body
2060
- * @param folderId - Required folder ID
2061
- * @param options - Optional query parameters
2062
- * @returns Promise resolving to the created jobs
2063
- *
2064
- * @example
2065
- * ```typescript
2066
- * import { Processes } from '@uipath/uipath-typescript/processes';
2067
- *
2068
- * const processes = new Processes(sdk);
2069
- *
2070
- * // Start a process by process key
2071
- * const jobs = await processes.start({
2072
- * processKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2073
- * }, 123); // folderId is required
2074
- *
2075
- * // Start a process by name with specific robots
2076
- * const jobs = await processes.start({
2077
- * processName: "MyProcess"
2078
- * }, 123); // folderId is required
2079
- * ```
2080
- */
2081
- async start(request, folderId, options = {}) {
2082
- const headers = createHeaders({ [FOLDER_ID]: folderId });
2069
+ async start(request, optionsOrFolderId, legacyOptions) {
2070
+ // Normalize the two overload forms into a single internal shape.
2071
+ let folderId;
2072
+ let folderKey;
2073
+ let folderPath;
2074
+ let queryOptions;
2075
+ if (typeof optionsOrFolderId === 'number') {
2076
+ // Deprecated positional form: start(request, folderId, options?)
2077
+ folderId = optionsOrFolderId;
2078
+ queryOptions = legacyOptions ?? {};
2079
+ }
2080
+ else {
2081
+ // Preferred form: start(request, options?)
2082
+ const { folderId: fid, folderKey: fkey, folderPath: fpath, ...rest } = optionsOrFolderId ?? {};
2083
+ folderId = fid;
2084
+ folderKey = fkey;
2085
+ folderPath = fpath;
2086
+ queryOptions = rest;
2087
+ }
2088
+ const headers = resolveFolderHeaders({
2089
+ folderId,
2090
+ folderKey,
2091
+ folderPath,
2092
+ resourceType: 'processes.start',
2093
+ fallbackFolderKey: this.config.folderKey,
2094
+ });
2083
2095
  // Transform SDK field names to API field names (e.g., processKey → releaseKey)
2084
2096
  const apiRequest = transformRequest(request, ProcessMap);
2085
2097
  // Create the request object according to API spec
@@ -2087,8 +2099,8 @@ class ProcessService extends FolderScopedService {
2087
2099
  startInfo: apiRequest
2088
2100
  };
2089
2101
  // Prefix all query parameter keys with '$' for OData
2090
- const keysToPrefix = Object.keys(options);
2091
- const apiOptions = addPrefixToKeys(options, ODATA_PREFIX, keysToPrefix);
2102
+ const keysToPrefix = Object.keys(queryOptions);
2103
+ const apiOptions = addPrefixToKeys(queryOptions, ODATA_PREFIX, keysToPrefix);
2092
2104
  const response = await this.post(PROCESS_ENDPOINTS.START_PROCESS, requestBody, {
2093
2105
  params: apiOptions,
2094
2106
  headers
@@ -744,6 +744,17 @@ interface ProcessGetByIdOptions extends BaseOptions {
744
744
  */
745
745
  interface ProcessGetByNameOptions extends FolderScopedOptions {
746
746
  }
747
+ /**
748
+ * Options for starting a process. Combines folder scoping
749
+ * (`folderId` / `folderKey` / `folderPath`) with the OData query options
750
+ * (`expand`, `select`, `filter`, `orderby`) accepted by the start endpoint.
751
+ *
752
+ * Folder scoping is optional in the type — the SDK falls back to the
753
+ * init-time folderKey (e.g. `<meta name="uipath:folder-key">` in coded-app
754
+ * deployments). A `ValidationError` is raised when neither is provided.
755
+ */
756
+ interface ProcessStartOptions extends FolderScopedOptions, RequestOptions {
757
+ }
747
758
 
748
759
  /**
749
760
  * Service for managing and executing UiPath Automation Processes.
@@ -840,26 +851,45 @@ interface ProcessServiceModel {
840
851
  */
841
852
  getByName(name: string, options?: ProcessGetByNameOptions): Promise<ProcessGetResponse>;
842
853
  /**
843
- * Starts a process with the specified configuration
854
+ * Starts a process with the specified configuration.
855
+ *
856
+ * Folder context can be supplied as `folderId`, `folderKey`, or `folderPath`
857
+ * inside the options.
844
858
  *
845
859
  * @param request - Process start configuration
846
- * @param folderId - Required folder ID
847
- * @param options - Optional request options
860
+ * @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`) and optional query parameters (`expand`, `select`, `filter`, `orderby`)
848
861
  * @returns Promise resolving to array of started process instances
849
862
  * {@link ProcessStartResponse}
850
863
  * @example
851
864
  * ```typescript
852
- * // Start a process by process key
853
- * const result = await processes.start({
854
- * processKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
855
- * }, <folderId>); // folderId is required
856
- *
857
- * // Start a process by name with specific robots
858
- * const result = await processes.start({
859
- * processName: "MyProcess"
860
- * }, <folderId>); // folderId is required
865
+ * // By folder ID
866
+ * await processes.start({ processKey: '<processKey>' }, { folderId: <folderId> });
867
+ *
868
+ * // By folder key (GUID)
869
+ * await processes.start({ processKey: '<processKey>' }, { folderKey: '5f6dadf1-3677-49dc-8aca-c2999dd4b3ba' });
870
+ *
871
+ * // By folder path
872
+ * await processes.start({ processKey: '<processKey>' }, { folderPath: 'Shared/Finance' });
873
+ *
874
+ * // Start by process name (instead of processKey)
875
+ * await processes.start({ processName: 'MyProcess' }, { folderId: <folderId> });
876
+ *
877
+ * // With additional options
878
+ * await processes.start({ processKey: '<processKey>' }, { folderId: <folderId>, expand: 'Robot' });
861
879
  * ```
862
880
  */
881
+ start(request: ProcessStartRequest, options?: ProcessStartOptions): Promise<ProcessStartResponse[]>;
882
+ /**
883
+ * Starts a process — positional `folderId` form.
884
+ *
885
+ * @deprecated Use the options-object form: `start(request, { folderId })`. See {@link ProcessStartOptions} for the supported options.
886
+ *
887
+ * @param request - Process start configuration
888
+ * @param folderId - Required folder ID (numeric)
889
+ * @param options - Optional request options
890
+ * @returns Promise resolving to array of started process instances
891
+ * {@link ProcessStartResponse}
892
+ */
863
893
  start(request: ProcessStartRequest, folderId: number, options?: RequestOptions): Promise<ProcessStartResponse[]>;
864
894
  }
865
895
 
@@ -913,12 +943,15 @@ declare class ProcessService extends FolderScopedService implements ProcessServi
913
943
  */
914
944
  getAll<T extends ProcessGetAllOptions = ProcessGetAllOptions>(options?: T): Promise<T extends HasPaginationOptions<T> ? PaginatedResponse<ProcessGetResponse> : NonPaginatedResponse<ProcessGetResponse>>;
915
945
  /**
916
- * Starts a process execution (job)
946
+ * Starts a process with the specified configuration.
917
947
  *
918
- * @param request - Process start request body
919
- * @param folderId - Required folder ID
920
- * @param options - Optional query parameters
921
- * @returns Promise resolving to the created jobs
948
+ * Folder context can be supplied as `folderId`, `folderKey`, or `folderPath`
949
+ * inside the options.
950
+ *
951
+ * @param request - Process start configuration
952
+ * @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`) and optional query parameters (`expand`, `select`, `filter`, `orderby`)
953
+ * @returns Promise resolving to array of started process instances
954
+ * {@link ProcessStartResponse}
922
955
  *
923
956
  * @example
924
957
  * ```typescript
@@ -926,17 +959,34 @@ declare class ProcessService extends FolderScopedService implements ProcessServi
926
959
  *
927
960
  * const processes = new Processes(sdk);
928
961
  *
929
- * // Start a process by process key
930
- * const jobs = await processes.start({
931
- * processKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
932
- * }, 123); // folderId is required
962
+ * // By folder ID
963
+ * await processes.start({ processKey: '<processKey>' }, { folderId: <folderId> });
933
964
  *
934
- * // Start a process by name with specific robots
935
- * const jobs = await processes.start({
936
- * processName: "MyProcess"
937
- * }, 123); // folderId is required
965
+ * // By folder key (GUID)
966
+ * await processes.start({ processKey: '<processKey>' }, { folderKey: '5f6dadf1-3677-49dc-8aca-c2999dd4b3ba' });
967
+ *
968
+ * // By folder path
969
+ * await processes.start({ processKey: '<processKey>' }, { folderPath: 'Shared/Finance' });
970
+ *
971
+ * // Start by process name (instead of processKey)
972
+ * await processes.start({ processName: 'MyProcess' }, { folderId: <folderId> });
973
+ *
974
+ * // With additional options
975
+ * await processes.start({ processKey: '<processKey>' }, { folderId: <folderId>, expand: 'Robot' });
938
976
  * ```
939
977
  */
978
+ start(request: ProcessStartRequest, options?: ProcessStartOptions): Promise<ProcessStartResponse[]>;
979
+ /**
980
+ * Starts a process — positional `folderId` form.
981
+ *
982
+ * @deprecated Use the options-object form: `start(request, { folderId })`. See {@link ProcessStartOptions} for the supported options.
983
+ *
984
+ * @param request - Process start configuration
985
+ * @param folderId - Required folder ID (numeric)
986
+ * @param options - Optional request options
987
+ * @returns Promise resolving to array of started process instances
988
+ * {@link ProcessStartResponse}
989
+ */
940
990
  start(request: ProcessStartRequest, folderId: number, options?: RequestOptions): Promise<ProcessStartResponse[]>;
941
991
  /**
942
992
  * Gets a single process by ID
@@ -987,4 +1037,4 @@ declare class ProcessService extends FolderScopedService implements ProcessServi
987
1037
  }
988
1038
 
989
1039
  export { JobPriority, JobSourceType, JobType, PackageSourceType, PackageType, ProcessService, ProcessService as Processes, RemoteControlAccess, RobotSize, RuntimeType, StartStrategy, StopStrategy, TargetFramework };
990
- export type { ArgumentMetadata, BaseProcessStartRequest, FolderProperties, JobAttachment, JobError, Machine, ProcessGetAllOptions, ProcessGetByIdOptions, ProcessGetByNameOptions, ProcessGetResponse, ProcessProperties, ProcessServiceModel, ProcessStartRequest, ProcessStartRequestWithKey, ProcessStartRequestWithName, ProcessStartResponse, RobotMetadata };
1040
+ export type { ArgumentMetadata, BaseProcessStartRequest, FolderProperties, JobAttachment, JobError, Machine, ProcessGetAllOptions, ProcessGetByIdOptions, ProcessGetByNameOptions, ProcessGetResponse, ProcessProperties, ProcessServiceModel, ProcessStartOptions, ProcessStartRequest, ProcessStartRequestWithKey, ProcessStartRequestWithName, ProcessStartResponse, RobotMetadata };
@@ -611,14 +611,25 @@ class ApiClient {
611
611
  if (!text) {
612
612
  return undefined;
613
613
  }
614
- return JSON.parse(text);
614
+ try {
615
+ return JSON.parse(text);
616
+ }
617
+ catch (error) {
618
+ if (error instanceof SyntaxError) {
619
+ throw new ServerError({
620
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
621
+ statusCode: response.status,
622
+ });
623
+ }
624
+ throw error;
625
+ }
615
626
  }
616
627
  catch (error) {
617
628
  // If it's already one of our errors, re-throw it
618
629
  if (error.type && error.type.includes('Error')) {
619
630
  throw error;
620
631
  }
621
- // Otherwise, it's likely a network error
632
+ // Otherwise, it's a genuine network/fetch failure
622
633
  throw ErrorFactory.createNetworkError(error);
623
634
  }
624
635
  }
@@ -1282,9 +1293,9 @@ class PaginationHelpers {
1282
1293
  * @returns Promise resolving to a paginated result
1283
1294
  */
1284
1295
  static async getAllPaginated(params) {
1285
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1296
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1286
1297
  const endpoint = getEndpoint(folderId);
1287
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1298
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1288
1299
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1289
1300
  headers,
1290
1301
  params: additionalParams,
@@ -1312,13 +1323,13 @@ class PaginationHelpers {
1312
1323
  * @returns Promise resolving to an object with data and totalCount
1313
1324
  */
1314
1325
  static async getAllNonPaginated(params) {
1315
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1326
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1316
1327
  // Set default field names
1317
1328
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1318
1329
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1319
1330
  // Determine endpoint and headers based on folderId
1320
1331
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1321
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1332
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1322
1333
  // Make the API call based on method
1323
1334
  let response;
1324
1335
  if (method === HTTP_METHODS.POST) {
@@ -1377,6 +1388,7 @@ class PaginationHelpers {
1377
1388
  serviceAccess: config.serviceAccess,
1378
1389
  getEndpoint: config.getEndpoint,
1379
1390
  folderId,
1391
+ headers: config.headers,
1380
1392
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1381
1393
  additionalParams: prefixedOptions,
1382
1394
  transformFn: config.transformFn,
@@ -1394,6 +1406,7 @@ class PaginationHelpers {
1394
1406
  getAllEndpoint: config.getEndpoint(),
1395
1407
  getByFolderEndpoint: byFolderEndpoint,
1396
1408
  folderId,
1409
+ headers: config.headers,
1397
1410
  additionalParams: prefixedOptions,
1398
1411
  transformFn: config.transformFn,
1399
1412
  method: config.method,
@@ -2051,33 +2064,32 @@ class ProcessService extends FolderScopedService {
2051
2064
  }
2052
2065
  }, options);
2053
2066
  }
2054
- /**
2055
- * Starts a process execution (job)
2056
- *
2057
- * @param request - Process start request body
2058
- * @param folderId - Required folder ID
2059
- * @param options - Optional query parameters
2060
- * @returns Promise resolving to the created jobs
2061
- *
2062
- * @example
2063
- * ```typescript
2064
- * import { Processes } from '@uipath/uipath-typescript/processes';
2065
- *
2066
- * const processes = new Processes(sdk);
2067
- *
2068
- * // Start a process by process key
2069
- * const jobs = await processes.start({
2070
- * processKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2071
- * }, 123); // folderId is required
2072
- *
2073
- * // Start a process by name with specific robots
2074
- * const jobs = await processes.start({
2075
- * processName: "MyProcess"
2076
- * }, 123); // folderId is required
2077
- * ```
2078
- */
2079
- async start(request, folderId, options = {}) {
2080
- const headers = createHeaders({ [FOLDER_ID]: folderId });
2067
+ async start(request, optionsOrFolderId, legacyOptions) {
2068
+ // Normalize the two overload forms into a single internal shape.
2069
+ let folderId;
2070
+ let folderKey;
2071
+ let folderPath;
2072
+ let queryOptions;
2073
+ if (typeof optionsOrFolderId === 'number') {
2074
+ // Deprecated positional form: start(request, folderId, options?)
2075
+ folderId = optionsOrFolderId;
2076
+ queryOptions = legacyOptions ?? {};
2077
+ }
2078
+ else {
2079
+ // Preferred form: start(request, options?)
2080
+ const { folderId: fid, folderKey: fkey, folderPath: fpath, ...rest } = optionsOrFolderId ?? {};
2081
+ folderId = fid;
2082
+ folderKey = fkey;
2083
+ folderPath = fpath;
2084
+ queryOptions = rest;
2085
+ }
2086
+ const headers = resolveFolderHeaders({
2087
+ folderId,
2088
+ folderKey,
2089
+ folderPath,
2090
+ resourceType: 'processes.start',
2091
+ fallbackFolderKey: this.config.folderKey,
2092
+ });
2081
2093
  // Transform SDK field names to API field names (e.g., processKey → releaseKey)
2082
2094
  const apiRequest = transformRequest(request, ProcessMap);
2083
2095
  // Create the request object according to API spec
@@ -2085,8 +2097,8 @@ class ProcessService extends FolderScopedService {
2085
2097
  startInfo: apiRequest
2086
2098
  };
2087
2099
  // Prefix all query parameter keys with '$' for OData
2088
- const keysToPrefix = Object.keys(options);
2089
- const apiOptions = addPrefixToKeys(options, ODATA_PREFIX, keysToPrefix);
2100
+ const keysToPrefix = Object.keys(queryOptions);
2101
+ const apiOptions = addPrefixToKeys(queryOptions, ODATA_PREFIX, keysToPrefix);
2090
2102
  const response = await this.post(PROCESS_ENDPOINTS.START_PROCESS, requestBody, {
2091
2103
  params: apiOptions,
2092
2104
  headers
@@ -613,14 +613,25 @@ class ApiClient {
613
613
  if (!text) {
614
614
  return undefined;
615
615
  }
616
- return JSON.parse(text);
616
+ try {
617
+ return JSON.parse(text);
618
+ }
619
+ catch (error) {
620
+ if (error instanceof SyntaxError) {
621
+ throw new ServerError({
622
+ message: `Server returned non-JSON response (${response.status} ${response.url}): ${error.message}`,
623
+ statusCode: response.status,
624
+ });
625
+ }
626
+ throw error;
627
+ }
617
628
  }
618
629
  catch (error) {
619
630
  // If it's already one of our errors, re-throw it
620
631
  if (error.type && error.type.includes('Error')) {
621
632
  throw error;
622
633
  }
623
- // Otherwise, it's likely a network error
634
+ // Otherwise, it's a genuine network/fetch failure
624
635
  throw ErrorFactory.createNetworkError(error);
625
636
  }
626
637
  }
@@ -1221,9 +1232,9 @@ class PaginationHelpers {
1221
1232
  * @returns Promise resolving to a paginated result
1222
1233
  */
1223
1234
  static async getAllPaginated(params) {
1224
- const { serviceAccess, getEndpoint, folderId, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1235
+ const { serviceAccess, getEndpoint, folderId, headers: providedHeaders, paginationParams, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1225
1236
  const endpoint = getEndpoint(folderId);
1226
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1237
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1227
1238
  const paginatedResponse = await serviceAccess.requestWithPagination(method, endpoint, paginationParams, {
1228
1239
  headers,
1229
1240
  params: additionalParams,
@@ -1251,13 +1262,13 @@ class PaginationHelpers {
1251
1262
  * @returns Promise resolving to an object with data and totalCount
1252
1263
  */
1253
1264
  static async getAllNonPaginated(params) {
1254
- const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1265
+ const { serviceAccess, getAllEndpoint, getByFolderEndpoint, folderId, headers: providedHeaders, additionalParams, transformFn, method = HTTP_METHODS.GET, options = {} } = params;
1255
1266
  // Set default field names
1256
1267
  const itemsField = options.itemsField || DEFAULT_ITEMS_FIELD;
1257
1268
  const totalCountField = options.totalCountField || DEFAULT_TOTAL_COUNT_FIELD;
1258
1269
  // Determine endpoint and headers based on folderId
1259
1270
  const endpoint = folderId ? getByFolderEndpoint : getAllEndpoint;
1260
- const headers = folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {};
1271
+ const headers = providedHeaders ?? (folderId ? createHeaders({ [FOLDER_ID]: folderId }) : {});
1261
1272
  // Make the API call based on method
1262
1273
  let response;
1263
1274
  if (method === HTTP_METHODS.POST) {
@@ -1316,6 +1327,7 @@ class PaginationHelpers {
1316
1327
  serviceAccess: config.serviceAccess,
1317
1328
  getEndpoint: config.getEndpoint,
1318
1329
  folderId,
1330
+ headers: config.headers,
1319
1331
  paginationParams: cursor ? { cursor, pageSize } : jumpToPage ? { jumpToPage, pageSize } : { pageSize },
1320
1332
  additionalParams: prefixedOptions,
1321
1333
  transformFn: config.transformFn,
@@ -1333,6 +1345,7 @@ class PaginationHelpers {
1333
1345
  getAllEndpoint: config.getEndpoint(),
1334
1346
  getByFolderEndpoint: byFolderEndpoint,
1335
1347
  folderId,
1348
+ headers: config.headers,
1336
1349
  additionalParams: prefixedOptions,
1337
1350
  transformFn: config.transformFn,
1338
1351
  method: config.method,