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,129 @@ 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+ * A `ValidationError` is thrown when the `newValue` type does not match.
176+ *
177+ * Returns void; the API does not return the updated asset, so call
178+ * {@link AssetService.getById} or {@link AssetService.getByName} if you need
179+ * the refreshed value.
180+ *
181+ * @param id - Asset ID
182+ * @param newValue - New value to apply (string for `Text`, number for `Integer`, boolean for `Bool`)
183+ * @param options - Folder scoping (`folderId` / `folderKey` / `folderPath`)
184+ * @returns Promise resolving when the asset has been updated
185+ *
186+ * @example
187+ * ```typescript
188+ * import { Assets } from '@uipath/uipath-typescript/assets';
189+ *
190+ * const assets = new Assets(sdk);
191+ *
192+ * // Update a Text asset by folder ID
193+ * await assets.updateValueById(<assetId>, 'new-value', { folderId: <folderId> });
194+ *
195+ * // Update an Integer asset by folder key (GUID)
196+ * await assets.updateValueById(<assetId>, 42, { folderKey: '5f6dadf1-3677-49dc-8aca-c2999dd4b3ba' });
197+ *
198+ * // Update a Bool asset by folder path
199+ * await assets.updateValueById(<assetId>, true, { folderPath: 'Shared/Finance' });
200+ * ```
201+ */
202+ @track ( 'Assets.UpdateValueById' )
203+ async updateValueById ( id : number , newValue : AssetNewValue , options ?: AssetUpdateValueByIdOptions ) : Promise < void > {
204+ if ( ! id ) {
205+ throw new ValidationError ( { message : 'id is required for updateValueById' } ) ;
206+ }
207+ if ( newValue === null || newValue === undefined ) {
208+ throw new ValidationError ( { message : 'newValue is required for updateValueById' } ) ;
209+ }
210+
211+ const headers = resolveFolderHeaders ( {
212+ folderId : options ?. folderId ,
213+ folderKey : options ?. folderKey ,
214+ folderPath : options ?. folderPath ,
215+ resourceType : 'Assets.updateValueById' ,
216+ fallbackFolderKey : this . config . folderKey ,
217+ } ) ;
218+
219+ const existingResponse = await this . get < {
220+ Name : string ;
221+ ValueScope : AssetValueScope ;
222+ ValueType : AssetValueType ;
223+ Description : string | null ;
224+ } > (
225+ ASSET_ENDPOINTS . GET_BY_ID ( id ) ,
226+ { headers } ,
227+ ) ;
228+ const existing = existingResponse . data ;
229+
230+ const valueField = resolveValueField ( id , existing . ValueType , newValue ) ;
231+
232+ const body : Record < string , unknown > = {
233+ Id : id ,
234+ Name : existing . Name ,
235+ ValueScope : existing . ValueScope ,
236+ ValueType : existing . ValueType ,
237+ Description : existing . Description ,
238+ [ valueField ] : newValue ,
239+ } ;
240+
241+ await this . put (
242+ ASSET_ENDPOINTS . GET_BY_ID ( id ) ,
243+ body ,
244+ { headers } ,
245+ ) ;
246+ }
247+ }
248+
249+ /**
250+ * Maps the asset's `valueType` to the PUT body field carrying the new value, validating
251+ * that the new value's runtime type matches the asset type.
252+ */
253+ function resolveValueField (
254+ id : number ,
255+ valueType : AssetValueType ,
256+ newValue : AssetNewValue ,
257+ ) : 'StringValue' | 'IntValue' | 'BoolValue' {
258+ switch ( valueType ) {
259+ case AssetValueType . Text :
260+ if ( typeof newValue !== 'string' ) {
261+ throw new ValidationError ( {
262+ message : `Asset ${ id } has valueType Text; newValue must be a string, got ${ typeof newValue } ` ,
263+ } ) ;
264+ }
265+ return 'StringValue' ;
266+ case AssetValueType . Integer :
267+ if ( typeof newValue !== 'number' || ! Number . isInteger ( newValue ) ) {
268+ throw new ValidationError ( {
269+ message : `Asset ${ id } has valueType Integer; newValue must be an integer number, got ${ typeof newValue } ` ,
270+ } ) ;
271+ }
272+ return 'IntValue' ;
273+ case AssetValueType . Bool :
274+ if ( typeof newValue !== 'boolean' ) {
275+ throw new ValidationError ( {
276+ message : `Asset ${ id } has valueType Bool; newValue must be a boolean, got ${ typeof newValue } ` ,
277+ } ) ;
278+ }
279+ return 'BoolValue' ;
280+ default :
281+ throw new ValidationError ( {
282+ message : `updateValueById only supports Text, Integer, or Bool assets; asset ${ id } has valueType ${ valueType } ` ,
283+ } ) ;
284+ }
158285}
0 commit comments