GitHub Webhooks not working with HttpAction
Hi,
So I've been having this issue with GitHub API and convex, as I want to get an installation id when the user connects to GitHub, how do I get the url for the httpAction to add as a Webhook url for GitHub?
Also can someone take a look at my code as this is my first time working with the GitHub api
https://github.com/Cyberverse2/squid
GitHub
GitHub - CyberVerse2/squid
Contribute to CyberVerse2/squid development by creating an account on GitHub.
20 Replies
The url for http actions is
https://<your deployment name>.convex.site
, plus the route. So if I define a route:
and my deployment name is happy-animal-123
, the url would be:
HTTP actions are exposed via
convex/http.ts
- docs here: https://docs.convex.dev/functions/http-actions#defining-http-actionsHTTP Actions | Convex Developer Hub
HTTP actions allow you to build an HTTP API right in Convex!
Ok, so I have to deploy to prod to get a deployment name, right?
No, all deployments have names, including your dev deployment
You can find it in your project settings
Mine is blisfull salamander 460, but when I try to navigate to it, the browser just says "webpage not found"
If you've run
npx convex dev
successfully after adding your http.ts
file with at least one route configured, you can use https://blissful-salamander-460.convex.site/myRoute
to access itOk, if GitHub sends a post request to my httpAction function, would it reflect in my functions dashboard?
Yep
If you're trying to navigate to your deployment in a browser you'll get a 404
If you navigate to a configured route from an http action, however, that will work fine, or it will say "no matching routes found"
Ok, also, can I use the fs module in convex
There's no filesystem to reference in a convex function, they're serverless functions. That said, if you're trying to use
fs
for something other than interacting with the filesystem, it should load fine if you're using the node environment (I think, haven't actually tried it)
(not that there's much you can do with fs outside of interacting with the filesystem)Yeah, the thing is that I have a private key in pem format that I want to use for my octokit, wo I would need to read the data inside using fs.readfile?
Is there any other way I can achieve it without using fs?
Put it in an env var, although you may need to play with the string format to get it to work correctly
Ok, I would try that
I've done it but it's been a while. You'll probably need to take one of the approaches in the top two answers for this SO question, I think the method I used was closer to the accepted answer: https://stackoverflow.com/questions/55459528/using-private-key-in-a-env-file
Stack Overflow
Using private key in a .env file
I have a multiline private key in a gatsby .env file:
GATSBY_GOOGLE_CLIENT_ID="12345"
GATSBY_GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nflkdflkdf...\n-----END PRIVATE KEY-----"
In my gatsby-
obviously you'd have to adapt to using an env variable in convex dashboard and not an env file, but this should still apply
Oh, thanks @erquhart 🔥
Also, is there no way to view responses from the httpAction request?
I've successfully set up GitHub app installation, but I'm getting an error and I don't know what I'm doing wrong unless I see the response
I believe GitHub surfaces responses if you check out the settings for your GitHub app, cannot recall where that's at though
hmm I may be thinking of webhook deliveries, not sure if they do it with Apps
Quickest way to get visibility is to console log whatever you want to see from your function body, then check it out in the Convex dashboard logs view
Ok, lemme try that
The PEM format ignores whitespace, so you can just paste it into the env variable value field and it will work fine.
To debug HTTP actions you can log (via
consoe.log
) the response or anything else and then look the logs in your dashboard (or via npx convex logs
).Thanks @Michal Srb