Unable to create webhooks in Github

I was working on level3 in Play-Along in marketplace-sample-apps. I was following this tutorial Freshdesk Serverless App . I followed the same code I was able to create issue in github using “OnTicketCreate” event. But webhook is not registered in github and there is no error in browser console or terminal. At the start of the above mentioned tutorial page, there is a note I didn’t understand that, This is the note

Note: Since Github does not allow registration of localhost URLs for Webhooks, we can proceed with packing our app as a custom app. Another alternative is to use ngrok to tunnel the requests from Github to our local app

can anyone explain how to create webhook here? And when “onAppInstall” event will occur ?

Hi @vamsikri-hash,

First of all, I would like to welcome you to the forum :tada:

Could you please address here on how you ran the app? By local testing or in production?

If you tried with local testing, then you just need to run the app by using the command fdk run -tunnel instead of fdk run.

  • If you try with fdk run command, then the app will generate the target URL like http://localhost:{some_port_number}
  • If you try with fdk run -tunnel command, then the app will generate the target URL like https://{some_alphanumeric_charaters}.ngrok.io

Generally, the localhost URL doesn’t have a unique identity or https. Due to this, the webhook registration will fail. If you are using the localhost URL in the Github webhook settings, it can’t identify where to send the payload.

Click here to know how to invoke the onAppInstall event via local testing.

I hope this helps you.

3 Likes

Thanks for the response.

I tried fdk tunnel but it says tunnel is not valid command. So googled for that command and found this one fdk run --tunnel After starting the server in the testing page I invoked “onAppInstall” event after that github hook is successfully registered. But I was unable to close the ticket after closing the issue. This is tutorial page Testing External Events & Recap when I invoked the “onExternalEvent” It is showing success but not able to close the ticket. This is the error i am getting in console.

Error: Failed to get issue data. Unable to create ticket
{ status: 404, message: 'Record not found' }

JSON data used in “onExternalEvent”

{
  "account_id": 12345,
  "event": "onExternalEvent",
  "timestamp": 1500351361762,
  "domain": "https://sample.freshdesk.com",
  "options": "freshdesk.onExternalEvent",
  "data": "{ \"action\": \"closed\", \"issue\": { \"id\": 1, \"number\": 2, \"body\": \"a new issue created for a bug\", \"title\": \"bug issue\"  } }",
  "headers": {
    "Content-Type": "application/json"
  }
}

please help me resolving this .

Hi @vamsikri-hash

Thanks for correcting me on this fdk run --tunnel instead of fdk tunnel.

It looks like the mentioned ticket is not found under your Freshdesk account. Can you please change the ticket id to a valid one in the payload data?

I have mentioned that below

“data”: “{ “action”: “closed”, “issue”: { “id”: 1, “number”: {valid_ticket_number}, “body”: “a new issue created for a bug”, “title”: “bug issue” } }”

Can you please try this?

1 Like

Thanks for response.

By taking your inputs i was just debugging in terminal using the console.log(). While creating a ticket using “onTicketCreate” we are making post request to github issues api to create a issue. After that we are storing issueId and IssueNumber( which came from github as response) in db using saveMapping function. While storing , we are accessing Id and number using data.id and data.number but both are always storing as undefined . so I console data in terminal, it should be data.response.id and data.response.number because the response payload from github contains status,headers and response. So when I was invoking “onExternalEvent” it is searching for issue in db using issue number, but all issue numbers in db is undefined so I was always getting record not found.

When I changed data.id ,data.number to data.response.id, data.response.number and invoked the “onExternalEvent” with those details . I was able to close the ticket. So I think it is to be changed in this tutorial page Create issues :triangular_flag_on_post: in the saveMapping function.

Thanks for the tutorial and sample apps.