11import { FolderScopedService } from '../../folder-scoped' ;
2- import { AssetGetResponse , AssetGetAllOptions , AssetGetByIdOptions , AssetGetByNameOptions } from '../../../models/orchestrator/assets.types' ;
2+ import { AssetGetResponse , AssetGetAllOptions , AssetGetByIdOptions , AssetGetByNameOptions , AssetNewValue , AssetUpdateValueByIdOptions , AssetValueScope , AssetValueType } from '../../../models/orchestrator/assets.types' ;
33import { AssetServiceModel } from '../../../models/orchestrator/assets.models' ;
44import { addPrefixToKeys , pascalToCamelCaseKeys , transformData } from '../../../utils/transform' ;
55import { createHeaders } from '../../../utils/http/headers' ;
66import { FOLDER_ID } from '../../../utils/constants/headers' ;
7+ import { resolveFolderHeaders } from '../../../utils/folder/folder-headers' ;
78import { ASSET_ENDPOINTS } from '../../../utils/constants/endpoints' ;
89import { ODATA_PREFIX , ODATA_OFFSET_PARAMS } from '../../../utils/constants/common' ;
910import { AssetMap } from '../../../models/orchestrator/assets.constants' ;
@@ -12,6 +13,7 @@ import { PaginatedResponse, NonPaginatedResponse, HasPaginationOptions } from '.
1213import { PaginationHelpers } from '../../../utils/pagination/helpers' ;
1314import { PaginationType } from '../../../utils/pagination/internal-types' ;
1415import { track } from '../../../core/telemetry' ;
16+ import { ValidationError } from '../../../core/errors' ;
1517
1618/**
1719 * Service for interacting with UiPath Orchestrator Assets API
@@ -155,4 +157,123 @@ export class AssetService extends FolderScopedService implements AssetServiceMod
155157 ( raw ) => transformData ( pascalToCamelCaseKeys ( raw ) , AssetMap ) ,
156158 ) ;
157159 }
160+
161+ /**
162+ * Updates the value of an existing asset by ID.
163+ *
164+ * Fetches the asset internally to determine its type, then updates only the value while
165+ * preserving the asset's name, scope, and description.
166+ *
167+ * **Supported value types:** `Text`, `Integer`, and `Bool` only. Other types
168+ * (`Credential`, `Secret`) throw a `ValidationError`.
169+ *
170+ * The `newValue` runtime type must match the asset's `valueType`:
171+ * - `Text` → `string`
172+ * - `Integer` → `number` (integer)
173+ * - `Bool` → `boolean`
174+ *
175+ * @param id - Asset ID
176+ * @param newValue - New value to apply (string for `Text`, number for `Integer`, boolean for `Bool`)
177+ * @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`)
178+ * @returns Promise resolving when the asset has been updated
179+ *
180+ * @example
181+ * ```typescript
182+ * import { Assets } from '@uipath/uipath-typescript/assets';
183+ *
184+ * const assets = new Assets(sdk);
185+ *
186+ * // Update a Text asset by folder ID
187+ * await assets.updateValueById(<assetId>, 'new-value', { folderId: <folderId> });
188+ *
189+ * // Update an Integer asset by folder key (GUID)
190+ * await assets.updateValueById(<assetId>, 42, { folderKey: '5f6dadf1-3677-49dc-8aca-c2999dd4b3ba' });
191+ *
192+ * // Update a Bool asset by folder path
193+ * await assets.updateValueById(<assetId>, true, { folderPath: 'Shared/Finance' });
194+ * ```
195+ */
196+ @track ( 'Assets.UpdateValueById' )
197+ async updateValueById ( id : number , newValue : AssetNewValue , options ?: AssetUpdateValueByIdOptions ) : Promise < void > {
198+ if ( ! id ) {
199+ throw new ValidationError ( { message : 'id is required for updateValueById' } ) ;
200+ }
201+ if ( newValue === null || newValue === undefined ) {
202+ throw new ValidationError ( { message : 'newValue is required for updateValueById' } ) ;
203+ }
204+
205+ const headers = resolveFolderHeaders ( {
206+ folderId : options ?. folderId ,
207+ folderKey : options ?. folderKey ,
208+ folderPath : options ?. folderPath ,
209+ resourceType : 'Assets.updateValueById' ,
210+ fallbackFolderKey : this . config . folderKey ,
211+ } ) ;
212+
213+ const existingResponse = await this . get < {
214+ Name : string ;
215+ ValueScope : AssetValueScope ;
216+ ValueType : AssetValueType ;
217+ Description : string | null ;
218+ } > (
219+ ASSET_ENDPOINTS . GET_BY_ID ( id ) ,
220+ { headers } ,
221+ ) ;
222+ const existing = existingResponse . data ;
223+
224+ const valueField = resolveValueField ( id , existing . ValueType , newValue ) ;
225+
226+ const body : Record < string , unknown > = {
227+ Id : id ,
228+ Name : existing . Name ,
229+ ValueScope : existing . ValueScope ,
230+ ValueType : existing . ValueType ,
231+ Description : existing . Description ,
232+ [ valueField ] : newValue ,
233+ } ;
234+
235+ await this . put (
236+ ASSET_ENDPOINTS . GET_BY_ID ( id ) ,
237+ body ,
238+ { headers } ,
239+ ) ;
240+ }
241+ }
242+
243+ /**
244+ * Maps the asset's `valueType` to the PUT body field carrying the new value, validating
245+ * that the new value's runtime type matches the asset type.
246+ */
247+ function resolveValueField (
248+ id : number ,
249+ valueType : AssetValueType ,
250+ newValue : AssetNewValue ,
251+ ) : 'StringValue' | 'IntValue' | 'BoolValue' {
252+ switch ( valueType ) {
253+ case AssetValueType . Text :
254+ if ( typeof newValue !== 'string' ) {
255+ throw new ValidationError ( {
256+ message : `Asset ${ id } has valueType Text; newValue must be a string, got ${ typeof newValue } ` ,
257+ } ) ;
258+ }
259+ return 'StringValue' ;
260+ case AssetValueType . Integer :
261+ if ( typeof newValue !== 'number' || ! Number . isInteger ( newValue ) ) {
262+ throw new ValidationError ( {
263+ message : `Asset ${ id } has valueType Integer; newValue must be an integer number, got ${ typeof newValue } ` ,
264+ } ) ;
265+ }
266+ return 'IntValue' ;
267+ case AssetValueType . Bool :
268+ if ( typeof newValue !== 'boolean' ) {
269+ throw new ValidationError ( {
270+ message : `Asset ${ id } has valueType Bool; newValue must be a boolean, got ${ typeof newValue } ` ,
271+ } ) ;
272+ }
273+ return 'BoolValue' ;
274+ default :
275+ throw new ValidationError ( {
276+ message : `updateValueById only supports Text, Integer, or Bool assets; asset ${ id } has valueType ${ valueType } ` ,
277+ } ) ;
278+ }
158279}
0 commit comments