Trying to update an just created account via JMAP with an alias

Your question

I’m trying to update a new account with the following JMAP request:

{
    "using": [
        "urn:ietf:params:jmap:core",
        "urn:stalwart:jmap"
    ],
    "methodCalls": [
        [
            "x:Account/set",
            {
                "update": {
                    "e": {
                        "aliases": [
                            {
                                "enabled": true,
                                "name": "t.est",
                                "domainId": "b",
                                "description": null
                            }
                        ]
                    }
                }
            },
            "a"
        ]
    ]
}

But I get the following response:

{
   "methodResponses":[
      ["x:Account\/set",{
         "accountId":"b",
         "notUpdated":{
            "e":{
               "type":"invalidPatch",
               "description":"Invalid value for object property",
               "properties":["aliases"]
       }}},"a"]
   ],
   "sessionState":"da906780"
}

Any ideas?
Aliases is supposed to be an array, at least it’s returned as one for existing accounts with aliases.

Ralf

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Let me look into the JMAP Account/set API and how aliases are structured in Stalwart.

The key clue is right in the docs create example: "aliases": {} – the API uses {} (an object/map) for these list-type fields, not []. Let me confirm how patches to list items work in Stalwart’s JMAP implementation.

So I changed the request for aliases to be a map:

{
    "using": [
        "urn:ietf:params:jmap:core",
        "urn:stalwart:jmap"
    ],
    "methodCalls": [
        [
            "x:Account/set",
            {
                "update": {
                    "e": {
                        "aliases": {
                            "new0": {
                                "enabled": true,
                                "name": "t.est",
                                "domainId": "b",
                                "description": null
                            }
                        ]
                    }
                }
            },
            "a"
        ]
    ]
}

But I still get the following response :frowning:

{
   "methodResponses":[
      ["x:Account/set",{
        "accountId":"b",
        "notUpdated":{
           "e":{
              "type":"invalidPatch",
              "description":"Invalid key for object property",
              "properties":["aliases"]
       }}},"a"]
   ],
   "sessionState":"da906780"
}

I also tried not sending “description”: null, but got the same response :frowning:

Hmm, now I’m out of ideas …

Ralf

Same root cause as your other thread: aliases is a keyed map, not an array. It’s also returned to you as a map (keyed “0”, “1”, and so on), which is easy to misread as a plain array. Set it the same way:

{
  "using": ["urn:ietf:params:jmap:core","urn:stalwart:jmap"],
  "methodCalls": [
    ["x:Account/set",
      { "update": {
          "e": { "aliases": { "0": { "enabled": true, "name": "t.est", "domainId": "b", "description": null } } }
      } },
      "c1"
    ]
  ]
}

The keys have to be integer strings, so “new0” is rejected with the invalid-key error; use “0”, “1”, etc. If you only want to touch a single alias you can also patch it directly with a pointer key, “aliases/0”: { … }. The array form is what’s producing the invalidPatch.