Skip to content
Back

Server Update Document

  • 0
  • Databases
  • Functions
  • Cloud
Red
4 Nov, 2024, 00:09

Hello how do I get the user session if it's not directly from a user?

TypeScript

const client = new sdk.Client()
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('<YOUR_PROJECT_ID>') // Your project ID
    .setSession(''); // The user session to authenticate with

const databases = new sdk.Databases(client);

const result = await databases.updateDocument(
    '<DATABASE_ID>', // databaseId
    '<COLLECTION_ID>', // collectionId
    '<DOCUMENT_ID>', // documentId
    {}, // data (optional)
    ["read("any")"] // permissions (optional)
);```


A webhook is calling this function not directly from a user
TL;DR
The developer is having issues with dynamic API keys not letting them update the document in Appwrite. They tried self-generated API keys that worked but not the dynamic ones, even though they set the same scopes. They are unsure of how to get the user session if it's not directly from a user. A suggestion was made to wrap code in backticks for better readability. Solution: Determine the user with the Appwrite service. You can set up the user session directly in the code using the Appwrite Node.js SDK.
Steven
4 Nov, 2024, 00:17

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

Steven
4 Nov, 2024, 00:18

How do you expect Appwrite to know which user?

Red
4 Nov, 2024, 00:37

I just continued testing and noticed the dynamic api keys aren't letting me update the document, which Is why maybe I thought I need to set the session then I tried to use the self generated api keys, they work but not the dynamic, which is strange because I thought they're the same

I set the same scopes as well

Red
4 Nov, 2024, 00:38

I don't know if they're working as intended

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more