Here are my functions to GET and PUT the asset values:
def get_asset_value(access_token, organization_unit_id, base_url, asset_id):
url = f'{base_url}/odata/Assets({asset_id})'
headers = {
'Authorization': f'Bearer {access_token}',
'X-UIPATH-OrganizationUnitId': str(organization_unit_id),
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
response.raise_for_status() # Raise an error for bad status codes
return response.json().get('Value')
def set_asset_value(access_token, organization_unit_id, base_url, asset_id, new_value, field_name):
url = f'{base_url}/odata/Assets({asset_id})'
headers = {
'Authorization': f'Bearer {access_token}',
'X-UIPATH-OrganizationUnitId': str(organization_unit_id),
'Content-Type': 'application/json'
}
asset = {
"Name": field_name,
"Value": new_value
}
response = requests.put(url, json=asset, headers=headers)
response.raise_for_status()
The GET is working correctly. The PUT isn’t working with this error:
“Asset does not exist.”,“errorCode”:1002
I’m providing the correct name and id.
Also, why do I need to provide the name when I’m already providing the id? If the id is sufficient to GET it should suffice to PUT as well, right?