22 Replies
Yeah! You can use it from an action
It says that fetch is not defined
Not from a query or mutation as those must be deterministic
Check out actions
I'm using an HTTP endpoint
Actions allow you to call out to third party services
You can call an action from there
Do HTTP endpoints have to be deterministic?
I'm not using any queries or mutations
The function has to be callable from an HTTP request
Thinking… I believe http endpoints do not have to be deterministic, but I don’t think they have fetch available like actions. Let me double check this
Thanks for the question
ok yeah - check out limits here: https://docs.convex.dev/using/http-endpoints#limits.
Namely:
HTTP endpoints are run from the same Convex environment as queries and mutations, and have access to fewer built-in APIs. HTTP endpoints can call actions, which run in Node.js, if you want to use Node.js features.
To do what you're trying to do, I would recommend calling an action from your http endpoint and then it should work
appreciate the feedback though! Maybe there's a way we can make this more clear from the error message.
Darn, that would make things a good bit less complex if I could just use all the JS APIs from there
Thanks
Something like
And an action like this
Where do I specify the action name again?
https://docs.convex.dev/using/actions
There's two options.
1) will default to the filename in convex/actions/
2) Reference it as "filename:functionName"
Actions | Convex Developer Hub
Example:
ahh right. Thank you!
There's actually a better example in the queries section https://docs.convex.dev/using/writing-convex-functions#defining-convex-functions - but same idea for actions
Writing Convex Functions | Convex Developer Hub
Functions describe server behavior.
hell ya happy hacking
What package is
runAction()
exported from? I can't seem to find it in the convex package or the generated files. Might just be overlooking it lolol.It comes in the http context
Check the http endpoint doc for stuff to copy paste. It comes in as an argument
Is it
runRequest()
?
oh wait nvm
something like that
there we go :]
lots of good copy-pastables here https://docs.convex.dev/using/http-endpoints