Rank 1: Thread
I've been trying to get the Appwrite API to work in a Function, but I just can't seem to get it.
The function runs fine when I use just the Stripe API code, but once I start adding the Appwrite API to save some user preferences, it returns Execution timed out..
What I checked:
- I'm instantiating a new Appwrite client
- I'm setting
endPoint,setProject,setJWTto the Appwrite client - I'm creating the Appwrite
Accountclient - The Function initially had
Usersexecute access, but I triedAny, to no avail
When I log the client
{
"client": {
"endpoint": "https://backend.*****.com/v1",
"headers": {
"accept-encoding": "*",
"content-type": "",
"x-sdk-name": "Node.js",
"x-sdk-platform": "server",
"x-sdk-language": "nodejs",
"x-sdk-version": "11.0.0",
"X-Appwrite-Response-Format": "1.4.0",
"x-appwrite-project": "******",
"x-appwrite-jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1*************"
},
"selfSigned": false
}
}
My /src/lib/appwrite.ts:
constructor(
APPWRITE_ENDPOINT: string,
APPWRITE_PROJECT_ID: string,
APPWRITE_USER_JWT: string,
) {
this.client = new Client();
this.account = new Account(this.client);
this.client
.setEndpoint(APPWRITE_ENDPOINT). // These are logging fine
.setProject(APPWRITE_PROJECT_ID) // These are logging fine
.setJWT(APPWRITE_USER_JWT); // These are logging fine
}
async getPreferences(
functionContext: AppwriteFunctionContext,
): Promise<Record<string, string>> {
try {
return await this.account.getPrefs();
} catch (err) {
functionContext.error(err); // It never seems to catch
}
return {};
}
My main.ts:
const userPreferences = await appwriteService.getPreferences(functionContext);
Any hint on what I'm doing wrong would be appreciated.