Question about how actions and calling 3rd party apis work, and .env variables.
I read the docs on these but it's still not really clear to me how things work and connect together.
I want to pass params so i can add a query or body to the fetch call in doSomething action from react front end code. Is this possible?
These were the examples in the docs.
import { action } from "./_generated/server";
export const doSomething = action({
args: {},
handler: async () => {
const data = await fetch("https://api.thirdpartyservice.com");
return data
},
});
import React from "react";
import { useAction } from "convex/react";
import { api } from "../convex/_generated/api";
export function MyApp() {
const performMyAction = useAction(api.myFunctions.doSomething);
const handleClick = () => {
performMyAction({ a: 1 });
};
// pass
handleClick to a button
// ...
}
3 Replies
Hi! See this example to have your action actually take in parameters. The code you have above doesn't have the
args
param in the handler function. https://docs.convex.dev/functions/actions#action-arguments-and-responsesActions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment
As for setting environment variables you have to do that in your deployment: https://docs.convex.dev/production/environment-variables
Environment Variables | Convex Developer Hub
Store and access environment variables in Convex
wow i just solved it haha, thank you 🙂