Assets API - Asset does not exist. 1002

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?

Hi @bart.wille,

Please follow below thread, should help you.

Regards
Sonali

@bart.wille

  1. First try the call in swagger to confirm if all parameters are correct
  2. Then check if the user has required permissions

Cheers

The correct answer is to add “Id” also in the json payload.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.