
my code: (message.txt)
my error:
sdk.js:3128 Uncaught TypeError: Cannot read properties of undefined (reading 'Appwrite')
at sdk.js:3128:25

the line sdk.js:3128
:
})(this.Appwrite = this.Appwrite || {}, null, window);

You don't need the import. Instead of new appwrite.Client()
would you please try new Appwrite.Client()
?

let me try that.

I think it works. the database init var would also be Appwrite.Database();
?
It is js
const client = new appwrite.Client()
const database = new Appwrite.Databases(client, "chat-msgs");

Now, New Problem:
ET https://cloud.appwrite.io/v1/databases/chat-msgs/collections/chat-msgs-collection/documents 401
(anonymous) @ sdk.js:381
(anonymous) @ sdk.js:25
n @ sdk.js:21
call @ sdk.js:341
(anonymous) @ sdk.js:1713
(anonymous) @ sdk.js:25
n @ sdk.js:21
listDocuments @ sdk.js:1700
fetchMessages @ (index):136
(anonymous) @ (index):156
(index):151 Error fetching messages from Cloud: AppwriteException: The current user is not authorized to perform the requested action.
at e.Client.<anonymous> (https://cdn.jsdelivr.net/npm/appwrite@13.0.1:7:19529)
at Generator.next (<anonymous>)
at r (https://cdn.jsdelivr.net/npm/appwrite@13.0.1:7:115)
AKA:
GET https://cloud.appwrite.io/v1/databases/chat-msgs/collections/chat-msgs-collection/documents
Error fetching messages from Cloud: AppwriteException: The current user is not authorized to perform the requested action.

My Code:
// Function to add a message to the list with timestamp
function addMessage(message) {
// Shortening it bc msg too long
}
var socket = io();
// Initialize the AppWrite client
const client = new Appwrite.Client();
client.setEndpoint('https://cloud.appwrite.io/v1'); // Your Appwrite Endpoint
client.setProject('privatetable-chat'); // Your project ID
// Initialize Database service
const database = new Appwrite.Databases(client, "chat-msgs");
// Event listener for form submission
document.getElementById('form').addEventListener('submit', function (e) {
// More shortening...
});
// Event listener for receiving messages
socket.on('message', function (message) {
addMessage(JSON.parse(message));
});
// Function to fetch messages from AppWrite
function fetchMessages() {
const response = database.listDocuments("chat-msgs", "chat-msgs-collection")
.then(function () {
console.log(response)
var messagesList = document.getElementById('messages');
messagesList.innerHTML = ''; // Clear existing messages
// Add each message to the list
response.documents.forEach(function (document) {
addMessage({
timestamp: timestamp,
data: message
});
});
})
.catch(function (error) {
console.error('Error fetching messages from Cloud: ', error);
});
}
// Call fetchMessages when the page loads to load existing messages
fetchMessages();

I don’t see you creating a Session anywhere here. Does you Collection have read permissions form All guests?

I don't know, and I don't know how. Please guide me

For authentication, see https://appwrite.io/docs/products/auth

For permissions, see https://appwrite.io/docs/products/databases/collections#permissions

Ok, I'll see this and get back to you.

Umm. The Appwrite Python SDK gives this error:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\appwrite\client.py", line 100, in call
response.raise_for_status()
File "C:\Program Files\Python38\lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://cloud.appwrite.io/v1/databases/chat-msgs/collections/chat-msgs-collection/documents
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\eventlet\hubs\hub.py", line 473, in fire_timers
timer()
File "C:\Program Files\Python38\lib\site-packages\eventlet\hubs\timer.py", line 59, in __call__
cb(*args, **kw)
File "C:\Program Files\Python38\lib\site-packages\eventlet\greenthread.py", line 222, in main
result = function(*args, **kwargs)
File "C:\Program Files\Python38\lib\site-packages\socketio\server.py", line 584, in _handle_event_internal
r = server._trigger_event(data[0], namespace, sid, *data[1:])
File "C:\Program Files\Python38\lib\site-packages\socketio\server.py", line 609, in _trigger_event
return self.handlers[namespace][event](*args)
File "script.py", line 67, in chat_message
document = database.create_document('chat-msgs','chat-msgs-collection', str(uuid.uuid4()), {'timestamp': timestamp, 'message': data})
File "C:\Program Files\Python38\lib\site-packages\appwrite\services\databases.py", line 945, in create_document
return self.client.call('post', api_path, {
File "C:\Program Files\Python38\lib\site-packages\appwrite\client.py", line 112, in call
raise AppwriteException(response.json()['message'], response.status_code, response.json().get('type'), response.json())
appwrite.exception.AppwriteException: Server Error
So, basically 500 Server Error from Appwrite's API...

if you want to see my full code, visit the GitHub

Firstly, you really shouldn’t be posting your API key publicly on the Internet

yeah, i know, I'll regenerate new one once everythings done

plus, it only has access to db

Best not to get into the habit of it!

Secondly, have you tried using Appwrite’s built in generator for your document ID? (Use the string ”unique()”

Yeah, I initially put this repo to private, but since I am too lazy to provide the full code each time, I set it to public

idk, I'll try it

Still, it’s best to never put secrets in Git repositories.

Always remember, down the line, even if you delete it, it’s still out there!

I deactivated it
Recommended threads
- Appwrite Fra Cloud Custom Domains Issue
I’m trying to configure my custom domain appwrite.qnarweb.com (CNAME pointing to fra.cloud.appwrite.io with Cloudflare proxy disabled) but encountering a TLS ce...
- Appwrite service :: getCurrentUser :: Us...
Getting this error while creating a react app can someone please help me solve the error
- Storage & Database is not allowing.
Storage & Database is not allowing to CRUD after i have logged in ? Using web SDK with next.js without any SSR or node-sdk.
