
i have no idea why my function is failing
deployed success message:
➜ webcrafts appwrite functions createDeployment --functionId=648077c945bd1641f0a1 --entrypoint='src/index.js' --code="./functions/likeCraftById" --activate=true
ℹ Info Ignoring files using configuration from appwrite.json
$id : 648086cf483237eb2bb0
$createdAt : 2023-06-07T13:31:59.380+00:00
$updatedAt : 2023-06-07T13:31:59.380+00:00
resourceId : 648077c945bd1641f0a1
resourceType : functions
entrypoint : src/index.js
size : 4485
buildId :
activate : true
status :
buildStdout :
buildStderr :
buildTime : 0

function code :
const sdk = require("node-appwrite");
module.exports = async function (req, res) {
const client = new sdk.Client();
const database = new sdk.Database(client);
const { craftId, likes } = JSON.parse(req.payload);
if (
!req.variables["APPWRITE_FUNCTION_ENDPOINT"] ||
!req.variables["APPWRITE_FUNCTION_API_KEY"]
) {
console.warn(
"Environment variables are not set. Function cannot use Appwrite SDK."
);
} else {
client
.setEndpoint(req.variables["APPWRITE_FUNCTION_ENDPOINT"])
.setProject(req.variables["APPWRITE_FUNCTION_PROJECT_ID"])
.setKey(req.variables["APPWRITE_FUNCTION_API_KEY"])
.setSelfSigned(true);
let newCraft = {};
if (craftId) {
try {
newCraft = await database.updateDocument(
req.variables["APPWRITE_FUNCTION_DATABASE_ID"],
req.variables["APPWRITE_FUNCTION_COLLECTION_ID"],
craftId,
{
likes,
}
);
return res.json({ data: newCraft });
} catch (e) {
console.error(e);
}
}
}
res.json({
areDevelopersAwesome: true,
});
};
this is how I am executing
try {
const functions = new Functions(client);
await functions.createExecution(
"FUNCTIoN_ID",
JSON.stringify({
craftId: craftid,
likes: likeCount + 1,
}),
true
);
setLikeCount(likeCount + 1);
setLiked(true);
} catch (error) {
console.log(error);
}


What's the error?

Check the image

It doesn't work


Sorry my bad

Okay, that mean the deployed function can't access the index.js
file

What I'll suggest is to use Appwrite cli for managing and deploying your functions

Like such

I used cli itself


.

I know, But using the full command approach
appwrite functions createDeployment --functionId=648077c945bd1641f0a1 --entrypoint='src/index.js' --code="./functions/likeCraftById" --activate=true
Can be sometime tricky

Ok so your suggestion is to run
Appwrite deploy function
Instead of full command

Yes, But it should be an Appwrite project before

Yup yup I did that

Thanks i will try that
Recommended threads
- Sharing cookies
Hi, I’m using Appwrite Cloud, and I have a setup where my Appwrite backend is hosted on a subdomain (e.g., api.example.com), while my frontend (Next.js app) and...
- Custom Domain Issue
i have added a custom domain about 21 hours ago, but till now there is no SSL certificate is active on it. but if i do DNS check via https://dnschecker.org/#C...
- Flutter OAuth2 Google does not return to...
When the flow starts, the browser opens, I select an account, and it keeps showing: """ Page not found The page you're looking for doesn't exist. `general_rout...
