Back

[SOLVED] Messaging API Failing with "SERVER ERROR"

  • 0
  • Functions
  • Messaging
  • Cloud
Zionnite
1 Feb, 2025, 11:23

Hello Appwrite Team,

I'm experiencing a "SERVER ERROR" whenever I attempt to send push notifications using the Messaging API. The function fails without clear details on what might be wrong.

Here’s the exact code I’m using:

TypeScript
    ID.unique(), // messageId
    'Don\'t Miss Your Prayer Partner!', // title
    'You have 24 hours to open the app or you will be set to inactive.', // body
    [], // topics (optional)
    [user.$id], // users (optional)
    [], // targets (optional)
    {
        fromName: 'Nosakhare',
        messageType: 'TEXT',
        message: 'You have 24 hours to open the app or you will be set to inactive',
        fromUserId: '0'
    }, // data (optional)
    'open_app', // action (optional)
    null, // image (optional)
    'default_icon', // icon (optional)
    'default', // sound (optional)
    '#6E0FAD', // color (optional)
    'inactivity_alert', // tag (optional)
    1, // badge (optional)
    false, // draft (optional)
    null // scheduledAt (optional)
);```

Everything seems correct based on the documentation, yet the API consistently returns a server error. Could you please check if this is an issue on Appwrite’s end or let me know if any modifications are required?
TL;DR
Issue: Developer facing "SERVER ERROR" when using Messaging API to send push notifications. Solution: Try modifying your code by including the correct parameters, like in the example below: ``` try { await messaging.createPush( ID.unique(), 'Don\'t Miss Your Prayer Partner!', 'You have 24 hours to open the app or you will be set to inactive.', [], [user.$id], [], { fromName: 'Nosakhare', messageType: 'TEXT', message: 'You have 24 hours to open the app or you will be set to inactive', from
Zionnite
1 Feb, 2025, 11:31

i added the below code for more info about the issues

TypeScript
log(`Detailed error for user ${user.$id}: ${JSON.stringify(error)}`);
log(`Error stack: ${error.stack}`);
log(`Failed to process user ${user.$id}: ${error.message}`);```

**so, here is the output of the log**

Failed to process user 2349034286339: Server Error Detailed error for user 2349034286339: {"name":"AppwriteException","code":500,"type":"general_unknown","response":{"message":"Server Error","code":500,"type":"general_unknown","version":"1.6.1"}} Error stack: AppwriteException: Server Error at _Client.call (file:///usr/local/server/src/function/node_modules/node-appwrite/dist/client.mjs:274:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Messaging.createPush (file:///usr/local/server/src/function/node_modules/node-appwrite/dist/services/messaging.mjs:276:12) at async processBatch (file:///usr/local/server/src/function/src/main.js:101:28) at async processNextChunk (file:///usr/local/server/src/function/src/main.js:40:7) at async Module.default (file:///usr/local/server/src/function/src/main.js:53:20) at async execute (/usr/local/server/src/server.js:208:16) at async action (/usr/local/server/src/server.js:225:7) at async /usr/local/server/src/server.js:14:5```

Zionnite
1 Feb, 2025, 11:53

if you are having issues like this, its a result of the structure of the Messaging api, below is what works for me

TypeScript
try {
  await messaging.createPush(
    ID.unique(),
    'Don\'t Miss Your Prayer Partner!',
    'You have 24 hours to open the app or you will be set to inactive.',
    [], 
    [user.$id],
    [],
    {
        fromName: 'Nosakhare',
        messageType: 'TEXT',
        message: 'You have 24 hours to open the app or you will be set to inactive',
        fromUserId: '0'
    },
    'open_app'
  );
} catch (error) {
    log(`Detailed error for user ${user.$id}: ${JSON.stringify(error)}`);
    // log(`Error stack: ${error.stack}`);
}
Zionnite
1 Feb, 2025, 11:53

[SOLVED] Messaging API Failing with "SERVER ERROR"

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