Back

why do functions fail when they actual succeed?

  • 0
  • Self Hosted
mauricev
16 Aug, 2023, 05:24

Consider this php function ```<?php

function sendEmailViaSendGrid($to, $subject, $text) { $apiKey = 'send_grid_api_key'; // Replace with your SendGrid API key

TypeScript
echo "Script Started\n";

$data = [
    'personalizations' => [
        [
            'to' => [
                ['email' => $to]
            ]
        ]
    ],
    'from' => ['email' => 'maurice.volaski@einsteinmed.edu'], // Replace with your email
    'subject' => $subject,
    'content' => [
        [
            'type' => 'text/plain',
            'value' => $text
        ]
    ]
];


$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, 'https://api.sendgrid.com/v3/mail/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);

$result = curl_exec($ch);


if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 202) {
    echo 'Email sent successfully.';
} else {
    echo 'Error in sending email: ' . $result;
}
echo "Script Ended\n";
curl_close($ch);

}

sendEmailViaSendGrid('&#112;&#114;&#111;&#103;&#114;&#97;&#x6d;&#109;&#x69;&#110;&#x67;&#x40;&#x66;&#x6c;&#x75;&#x78;&#x73;&#x6f;&#x66;&#116;&#46;&#x63;&#x6f;&#109;', 'Test Subject', 'Test Email Body');

?> ``` It actually sends the email, but in appwrite, I get 1) "no response recorded" 2) under Logs and errors, "internal runtime error". What is causing that and how come I don’t see anything echoed?

TL;DR
The issue is likely that the function is not returning anything as an execution output. Make sure to include a return statement in the function to fix this. Additionally, check if the function follows the required format as specified in the documentation.
darShan
16 Aug, 2023, 07:15
  1. no response recorded is probably because you did not return anything as an execution output.
  2. Not sure about this but there is a particular format for functions that needs to be followed, did you do that? See this section: https://appwrite.io/docs/functions#writingYourOwnFunction
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