Back

How appwrite functions actually work how to trigger those functions from client side

  • 0
  • React Native
  • Web
  • Functions
  • Cloud
mustaffa
4 Nov, 2024, 14:58

**here is the client side code ** const handleSubmit = async () => { console.log("Form submitted:", { landlordId, tenantDetails, selectedProperty, selectedUnit, }); debugger; try { const inviteCode = Math.floor(100000 + Math.random() * 900000).toString();

TypeScript
  await database.createDocument(
    config.databaseId,
    config.inviteCollectionId,
    ID.unique(),
    {
      code: inviteCode,
      landlord_id: landlordId,
      tenant_phone: tenantDetails.phone,
      property_id: selectedProperty.property_id,
      status: "pending",
      created_at: new Date().toISOString(),
      expires_at: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), // Expires in 24 hours
    }
  );
  console.log("invite added into database");
  // Execute Appwrite Function to send SMS

await functions.createExecution( "6727a2e1001f2c7ade1c", // Replace with your function ID JSON.stringify({ phone: tenantDetails.phone, code: inviteCode, }), false, "sms", ExecutionMethod.POST ); // console.log("Function executed successfully", res); alert("Invitation sent successfully!"); router.push("/"); } catch (error) { console.error("Error sending invite:", error); alert("Failed to send invitation. Please try again."); } };

i have already created a function in console and pass that function id into the createExecution method

but i want to know how this excution is trigger and how can i test it

TL;DR
Developers want to understand how to trigger Appwrite functions from the client-side. The code provided includes creating a document and executing an Appwrite function to send an SMS. To test the function execution, developers need to verify if the function is properly set up in the Appwrite console and connected to the client-side code with the correct function ID, parameters, and method (in this case, "sms" with POST execution). Once all configurations are correct, triggering the function should be successful.
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