Problem Statement: Inconsistent Document Creation with Appwrite Environment Variables in Node.js Function
I'm encountering an issue while creating documents using a Node.js function with Appwrite version 1.6.0. The problem occurs when using environment variables to set the endpoint and project ID, as introduced in Appwrite 1.6.0.
Current Behavior
- When using hardcoded values for the endpoint and project ID, document creation works as expected.
- When using environment variables (
process.env.APPWRITE_FUNCTION_API_ENDPOINTandprocess.env.APPWRITE_FUNCTION_PROJECT_ID), document creation fails silently.
Error Logs
documentX created with ID: 6710ffc800129bb4cfaf and data: {"name":"John Doe","age":30,"$id":"6710ffc800129bb4cfaf","$permissions":[],"$createdAt":"2024-10-17T12:15:04.549+00:00","$updatedAt":"2024-10-17T12:15:04.549+00:00","$databaseId":"6709f300000a8e07a263","$collectionId":"6710f9b5000395f9d3f0"}
documentY created with ID: undefined and data: {"total":1,"documents":[{"name":"John Doe","age":30,"$id":"6710ffc800129bb4cfaf","$createdAt":"2024-10-17T12:15:04.549+00:00","$updatedAt":"2024-10-17T12:15:04.549+00:00","$permissions":[],"$databaseId":"6709f300000a8e07a263","$collectionId":"6710f9b5000395f9d3f0"}]}
Note that documentY has an undefined ID and returns a list of documents instead of the created document.
Environment
- Appwrite version: 1.6.0
- Server: Self-hosted on Ubuntu 22.04
- Node.js version: 18.0
Steps to Reproduce
- Set up a self-hosted Appwrite instance (version 1.6.0) on Ubuntu 22.04.
- Copy the attached code into your function:
- Deploy the function to your Appwrite instance.
- Execute the function and observe the logs.
Expected Behavior
Both documentX and documentY should be created successfully, with valid IDs and correct data structures returned.
Any insights or suggestions to resolve this issue would be greatly appreciated. Thank you for your help!