Question:
WHY the callback inside elevate never executes???
Product:
In my Velo backend code, I’m trying to use the contacts.createContact API with elevate function, but the callback inside elevate never executes, I have tried many ways but none of them work, I need to createContact and return the contacted to trigger emails. Have everyone met similar situations?
What are you trying to achieve:
Here is my code , just to test if the elevate callback can be executed,
import { testElevate } from 'backend/test';
$w.onReady(function () {
$w('#testButton').onClick(() => runTest());
});
async function runTest() {
try {
$w('#resultText').text = "Testing...";
const result = await testElevate();
$w('#resultText').text = `Test result: ${result}`;
} catch (error) {
$w('#resultText').text = `Test failed: ${error.message}`;
}
}
Backend code:
export const testElevate = webMethod(
Permissions.Anyone,
async function() {
try {
console.log("[Test] Beginning elevate test");
console.log("[Test] Elevate type:", typeof elevate);
console.log("[Test] Before elevate call");
const testResult = await elevate(async () => {
console.log("[Test] Inside elevate callback - before basicElevateTest");
const result = await basicElevateTest();
console.log("[Test] Inside elevate callback - after basicElevateTest:", result);
return result;
});
console.log("[Test] After elevate call");
console.log("[Test] Elevate result:", testResult);
return testResult;
} catch (error) {
console.error("[Test] Elevate test failed:", error);
console.error("[Test] Error details:", {
message: error.message,
stack: error.stack
});
throw error;
}
}
);
Then you can see from logs, the callback didn’t executed, missing these two console.log
console.log(“[Test] Inside elevate callback - before basicElevateTest”); and console.log(“[Test] Inside elevate callback - after basicElevateTest:”, result);
What have you already tried:
No matter how I test, it can’t be called, if I write , change its structure like what I have seen from another post(in that post, the author could get a contact Promise) but for me is a forbidden error
const elevatedCreateContact = elevate(contacts.createContact);
console.log("After getting elevated function");
const newContact = await elevatedCreateContact(info, options);
console.log("Successfully created a new contact:", newContact);
console.log("Contact full object:", newContact);
console.log("Contact ID attempt 1:", newContact._id);
Then the log would have a code forbidden Error:
Message
message:
details:
applicationError;description: Forbiddencode: FORBIDDENdata: {}
Additional information:
Please help me - thank you in advance!