Don't think so
same problem with jwt - user is not authorized, even when all collections have all permissions available to "any"
removed all other fields from collection, only relation is present
tested other relations and only with twoWay relations there is such problem
so i just tested and i was able to create fine with an api key:
$ appwrite --json databases createDocument --databaseId "many-to-one" --collectionId "level1" --documentId "level1" --data '{
    "level2": {
        "$id": "level2",
        "level3": {
            "$id": "level3",
            "level4": {
                "$id": "level4",
                "level5": {
                    "$id": "level5"
                }
            }
        }
    }
}'
{
  "$id": "level1",
  "$permissions": [],
  "$createdAt": "2023-07-20T21:50:55.904+00:00",
  "$updatedAt": "2023-07-20T21:50:55.904+00:00",
  "level2": {
    "$id": "level2",
    "$createdAt": "2023-07-20T21:50:55.905+00:00",
    "$updatedAt": "2023-07-20T21:50:55.905+00:00",
    "$permissions": [],
    "level3": {
      "$id": "level3",
      "$createdAt": "2023-07-20T21:50:55.906+00:00",
      "$updatedAt": "2023-07-20T21:50:55.906+00:00",
      "$permissions": [],
      "$databaseId": "many-to-one",
      "$collectionId": "level3"
    },
    "$databaseId": "many-to-one",
    "$collectionId": "level2"
  },
  "$databaseId": "many-to-one",
  "$collectionId": "level1"
}
✓ Success
here are my collections:
Let me remove permissions:
and it still works:
$ appwrite --json databases createDocument --databaseId "many-to-one" --collectionId "level1" --documentId "level1" --data '{
    "level2": {
        "$id": "level2",
        "level3": {
            "$id": "level3",
            "level4": {
                "$id": "level4",
                "level5": {
                    "$id": "level5"
                }
            }
        }
    }
}'
{
  "$id": "level1",
  "$permissions": [],
  "$createdAt": "2023-07-20T21:54:59.591+00:00",
  "$updatedAt": "2023-07-20T21:54:59.591+00:00",
  "level2": {
    "$id": "level2",
    "$createdAt": "2023-07-20T21:54:59.592+00:00",
    "$updatedAt": "2023-07-20T21:54:59.592+00:00",
    "$permissions": [],
    "level3": {
      "$id": "level3",
      "$createdAt": "2023-07-20T21:54:59.593+00:00",
      "$updatedAt": "2023-07-20T21:54:59.593+00:00",
      "$permissions": [],
      "$databaseId": "many-to-one",
      "$collectionId": "level3"
    },
    "$databaseId": "many-to-one",
    "$collectionId": "level2"
  },
  "$databaseId": "many-to-one",
  "$collectionId": "level1"
}
✓ Success
Thanks a lot! Im comparing it to mine and in the meantime I will paste mine:
and insert try:
appwrite --json databases createDocument --databaseId "main_database" --collectionId "content_entry" --documentId "test1" --data '{"name":"test","assignedToCategories":[{"$id":"64b9b41199345ad2a55d"}]}'    
✗ Error The current user is not authorized to perform the requested action.
64b9b41199345ad2a55d is already existing object of type category
@Steven maybe problem is that im trying to insert document with relation from the "child" side?
ok, so its possible to create child or parent of the relation but cant reference it
also now getting 500
 appwrite --json databases updateDocument --databaseId "main_database" --collectionId "category" --documentId "k1" --data '{"content": ["c1"]}' --verbose
AppwriteException [Error]: Server Error
    at Client.call (/opt/homebrew/Cellar/appwrite/HEAD-b461997/libexec/lib/node_modules/appwrite-cli/lib/client.js:209:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async databasesUpdateDocument (/opt/homebrew/Cellar/appwrite/HEAD-b461997/libexec/lib/node_modules/appwrite-cli/lib/commands/databases.js:1353:16) {
  code: 500,
  response: [Object: null prototype] {
    message: 'Server Error',
    code: 500,
    type: 'general_unknown',
    version: '1.3.7',
    file: '/usr/src/code/vendor/utopia-php/database/src/Database/Database.php',
    line: 3090,
    trace: [
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype],
      [Object: null prototype]
    ]
  }
}
✗ Error Server Error
works from the "child" side
appwrite --json databases updateDocument --databaseId "main_database" --collectionId "content_entry" --documentId "c1" --data '{"assignedToCategories": ["k1"]}' --verbose
{
  "name": "c1",
  "$id": "c1",
  "$createdAt": "2023-07-20T22:59:38.347+00:00",
  "$updatedAt": "2023-07-20T23:03:52.676+00:00",
  "$permissions": [],
  "assignedToCategories": [
    {
      "name": "k1",
      "$id": "k1",
      "$createdAt": "2023-07-20T22:59:46.246+00:00",
      "$updatedAt": "2023-07-20T23:03:52.679+00:00",
      "$permissions": [],
      "$databaseId": "main_database",
      "$collectionId": "category"
    }
  ],
  "$databaseId": "main_database",
  "$collectionId": "content_entry"
}
✓ Success 
no error while creating, but no relation either:
 appwrite --json databases createDocument --databaseId "main_database" --collectionId "category" --documentId "k2" --data '{"name":"k2", "content": ["c1"]}' --verbose
{
  "name": "k2",
  "$id": "k2",
  "$permissions": [
    "read(\"user:64b43b2993b48df0d16b\")",
    "update(\"user:64b43b2993b48df0d16b\")",
    "delete(\"user:64b43b2993b48df0d16b\")"
  ],
  "$createdAt": "2023-07-20T23:05:14.443+00:00",
  "$updatedAt": "2023-07-20T23:05:14.443+00:00",
  "$databaseId": "main_database",
  "$collectionId": "category"
}
✓ Success 
are you trying to create those nested assignedCategories or link?
link
to link, you should put an array of ids rather than passing an array of objects
Yes! That was it! I was passing array of json objects with id instead of string array of ids
Thank you Steven, you saved the day again
[Solved] user_unauthorized in appwrite function using Server Dart SDK and API KEY
Recommended threads
- Deploying Function fails after several d...
I get the below issue on deploying to self hosted appwrite 1.8.0 functions, restarting the docker compose, or waiting a while, fixes it but is annoying. Any ide...
 - AI feature by functions?
I'm creating a website where, in short, users can index certain genealogical content. In connection with the development of AI, I was thinking about introducing...
 - Unknown usage from one of my database
I need support help. For more than 2 weeks, i didn't make any requests to my database, but I have noticed huge amount of reads and writes requests: Around 8000...