export const triggerApiCall = mutation({
args: { eventId: v.string() },
handler: async (ctx, { eventId }) => {
// Optionally insert a minimal record or just schedule the action
await ctx.scheduler.runAfter(0, internal.myFunctions.backgroundApiCall, { eventId });
},
});
export const backgroundApiCall = internalAction({
args: { eventId: v.string() },
handler: async (_, args) => {
// Call your third-party API here
},
});
Call the mutation from your frontend, not the action directly.
**Summary:**
Even if you don’t need to save data, using a mutation to schedule an action is the recommended and secure way to trigger background API calls from your frontend in Convex. Directly calling actions from the client is possible, but discouraged and considered an anti-pattern for privacy and security reasons. [Convex docs: Calling actions from clients](<https://docs.convex.dev/functions/actions#calling-actions-from-clients>) and [Zen of Convex](<https://docs.convex.dev/understanding/zen>).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------