-
I am trying to create a github app that receives webhooks events. As soon as an issue is created, the app will read content in the for some reason, I can't tell why, after supplying all the parameters to the RequestError [HttpError]: Unauthorized. "POST /repos/{owner}/{repo}/issues/{issue_number}/comments" failed most likely due to lack of authentication. Reason: "installation" key missing in webhook event payload Does anybody know how I can go about this? code is below const { App, createNodeMiddleware, Octokit } = require("octokit")
const { parsed: envs } = require("dotenv").config();
const SmeeClient = require("smee-client");
// instantiate Github App
const app = new App({
appId: envs.appId,
privateKey: envs.privateKey,
oauth: {
clientId: envs.clientId,
clientSecret: envs.clientSecret,
},
webhooks: { secret: envs.webhookSecret },
});
app.webhooks.on("issues.opened", async ({ octokit, payload }) => {
const {data: {content}} = await octokit.rest.repos.getContent({
owner: payload.repository.owner.login,
repo: payload.repository.name,
path: ".github/applicant-welcome.md"
})
await octokit.rest.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: content
}).then(()=>console.log("comment created")).catch(err=>console.error(err))
})
// create local server to receive webhooks
require("http").createServer(createNodeMiddleware(app)).listen(envs.PORT);
//connect local server to network client in development
if (process.env.NODE_ENV !== "production") {
const smee = new SmeeClient({
source: "https://smee.io/badging",
target: `http://localhost:${process.env.PORT}/api/github/webhooks`,
logger: console,
});
smee.start();
}
module.exports = { app }; |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Do you have the proper permissions on the app? You need to set the |
Beta Was this translation helpful? Give feedback.
-
The message seems to suggest that there is data missing from the webhook payload that is expected - namely the |
Beta Was this translation helpful? Give feedback.
-
@gr2m your last message reply to the above thread solved the problem. I think there was a conflict from the start. Now everything works like a charm. thank you |
Beta Was this translation helpful? Give feedback.
The message seems to suggest that there is data missing from the webhook payload that is expected - namely the
installation
key. Would you be able to logpayload
in yourapp.webhooks.on
callback, and share the output here?