Hello appwriter & team i'm trying to subscribe my already existing users to a topic but its not working, it just get stuck at a place
TypeScript
// This is your Appwrite function
// It's executed each time we get a request
export default async ({ req, res, log, error }) => {
const client = new Client();
client.setEndpoint(process.env.MY_APPWRITE_ENDPOINT).setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID).setKey(process.env.APPWRITE_API_KEY);
const functions = new Functions(client);
const database = new Databases(client);
const storage = new Storage(client);
const users = new Users(client);
const ENDPOINT = process.env.MY_APPWRITE_ENDPOINT;
const PROJECT_ID = process.env.APPWRITE_FUNCTION_PROJECT_ID;
const API_KEY = process.env.APPWRITE_API_KEY;
const DATABASE_ID = process.env.DATABASE_ID;
const USERS_ID = process.env.USERS_ID;
const SMS_PROVIDER_ID = process.env.SMS_PROVIDER_ID;
const EMAIL_PROVIDER_ID = process.env.EMAIL_PROVIDER_ID;
const PUSH_PROVIDER_ID = process.env.PUSH_PROVIDER_ID;
const GENERAL_TOPIC_ALL = process.env.GENERAL_TOPIC_ALL;
const GENERAL_TOPIC_SMS = process.env.GENERAL_TOPIC_SMS;
const GENERAL_TOPIC_PUSH = process.env.GENERAL_TOPIC_PUSH;
const GENERAL_TOPIC_EMAIL = process.env.GENERAL_TOPIC_EMAIL;
const data = JSON.parse(req.bodyRaw);
const subscribeType = data.type;
try{
TL;DR
Developers are experiencing issues with the createSubscriber endpoint in the Appwrite Cloud Function. The code appears to be getting stuck at a certain point. The issue might be due to handling multiple subscriber creations. They should check the logical flow for each subscribeType and refine the code accordingly, ensuring each messaging.createSubscriber call happens properly. It's also recommended to confirm the functionality with a simpler test scenario.TypeScript
const result = await users.list(
[Query.limit(500)]
);
const usersDocList = result.users;
log(`userList ${usersDocList.length}`);
for(let i=0; i<usersDocList.length; i++){
let usersList = usersDocList[i];
let userId = usersList.$id;
let userPhone = `+${usersList.$id}`;
let userEmail = usersList.email;
let targets = usersList.targets;
TypeScript
if(subscribeType == 'email'){
log(`Email sub`);
log(`UserId ${userId}`);
log(`UserId ${userEmail}`);
log(`targets ${targets.length}`);
for(let j= 0; j<targets.length; j++){
log(`email ${j}`);
if(targets[j].providerType == 'email'){
log(`started`); //================================================== IT GET STUCK HERE
await messaging.createSubscriber(
GENERAL_TOPIC_EMAIL, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
log(`done`);
}
}
}
TypeScript
for(let j= 0; j<targets.length; j++){
if(targets[j].providerType == 'sms'){
await messaging.createSubscriber(
GENERAL_TOPIC_SMS, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
}
}
}
else if(subscribeType == 'push'){
for(let j= 0; j<targets.length; j++){
if(targets[j].providerType == 'push'){
await messaging.createSubscriber(
GENERAL_TOPIC_PUSH, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
}
}
}
else if(subscribeType == 'all'){
for(let j= 0; j<targets.length; j++){
if(targets[j].providerType == 'email'){
await messaging.createSubscriber(
GENERAL_TOPIC_ALL, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
}
if(targets[j].providerType == 'sms'){
await messaging.createSubscriber(
GENERAL_TOPIC_ALL, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
}
if(targets[j].providerType == 'push'){
await messaging.createSubscriber(
GENERAL_TOPIC_ALL, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
}
}
}
}
}catch(appwriteErrors){
error(appwriteErrors);
}
return res.send({"data": "end like this"});
};```
now, i wrap the subscribe endpoint into try and catch, here is what i'm getting now
TypeScript
log(`Email sub`);
log(`UserId ${userId}`);
log(`UserId ${userEmail}`);
log(`targets ${targets.length}`);
for(let j= 0; j<targets.length; j++){
log(`email ${j}`);
if(targets[j].providerType == 'email'){
log(`started`);
try{
await messaging.createSubscriber(
GENERAL_TOPIC_EMAIL, // topicId
ID.unique(), // subscriberId
targets[j].$id // targetId
);
}catch(creatingError){
error({
"error":creatingError,
"depth":'creatingErrorEmail'
});
}
log(`done`);
}
}
}```
Appwrite Cloud Function - createSubscriber EndPoint not working
Recommended threads
- cant resume project
Invalid console fingerprint event i try man time
- TablesDB can't be used in Appwrite Funct...
I have written a function (DART) and it won't deploy. Here is what I get : 2026-03-14T17:09:41.459693680Z Compiling ... 2026-03-14T17:09:42.915619217Z ../build...
- general_route_not_found - Auth Guide
If you’ve just added a subdomain to your project, verified your DNS records, and confirmed your SSL certificate is working, but you're still hitting a `general_...