SOLVED Setting Nested Attribute with user.set_attribute API?

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
I'm trying to figure out how to set a nested attribute with the user.set_attribute API. If you retrieve information about a user using the GET based user API call you get amongst other things the following:

Code:
  {
    ...
    "microsoft_account": false,
    "attributes": {
      "preferences": {
        "platform": "freenas",
        "retroLogo": false,
        "timestamp": "2021-12-30T17:02:16.695Z",
        ...
        "dateFormat": "YYYY-MM-DD",
        "timeFormat": "HH:mm:ss",
        ...
        }
      }
    },
    "email": null,
    ...
  }


So clearly nested attributes are possible, however, I can't figure out how to specify the nesting via the API call. The basic API call is:

Code:
  midclt call user.set_attribute 1 "dateFormat" "MMMM d, yyyy"


But I need the "dateFormat" key to be nested inside "preferences" and I'm not sure how to accomplish that.

Thanks,
Harry
 

HarryMuscle

Contributor
Joined
Nov 15, 2021
Messages
161
So it turns out the answer is to use "preferences" as the key and then supply all of the existing key/value pairs including the modified ones as a valid JSON object string ("{ ... }") for the value for the "preferences" key. That means you can't overwrite just one nested value but need to retrieve all of them, update what needs updating, and then set all of them in one API call.

Thanks,
Harry
 
Top