Back

Appwrite Cloud - Updating Users Target

  • 0
  • Functions
  • Auth
  • Cloud
Zionnite
11 Jun, 2024, 23:45

Hello Appwriter, i'm trying to update the User Target in my Appwrite so that user can recieve sms, email or push notification from me, but i'm confuse what the <TARGET_ID> should be

here is my code

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;
  
  try{

    //GET ALL USERS IN ACCOUNT
    const result = await users.list(
      [Query.limit(500)]
    );
    const usersDocList = result.users;
 
    for(let i=0; i<usersDocList.length; i++){
      let usersList = usersDocList[i];
      
      if(usersList.targets.length === 0){
        //if user targets its empty then update users target 
        const result = await users.updateTarget(
          usersList.$id, // userId
          '<TARGET_ID>', // targetId
          'email', // identifier (optional)
          '6667553c000cde5ae310', // providerId (optional)
          'allUserTargetList' // name (optional)
        );

      }
    }

   
  }catch(appwriteErrors){

    error(appwriteErrors);
  }
  

  return res.send({"data": "end like this"});
  

};

please whats should be the value for the <TARGET_ID> is it the user Email that it's the target Id?

TL;DR
The `<TARGET_ID>` should be the ID associated with the target system, like the email service provider ID. It is not the user's email; it's a system identifier for the target.
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