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
- Cant configure email templates
i configure it on the console, and when i send the OTP, it sends with appwrite's email (instead of custom smtp) and with the branding, but i have the Pro (educa...
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?