# How to connect to webhook

**URL:** <https://integration.keap.com/t/how-to-connect-to-webhook/91350>\
**Category:** API Q&A\
**Tags:** web-hook\
**Created:** [September 7, 2023, 12:01am UTC](https://integration.keap.com/t/how-to-connect-to-webhook/91350 "2023-09-07T00:01:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michellia\_Herman](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@Michellia\_Herman](https://integration.keap.com/u/Michellia_Herman)\
**Post date:** [September 7, 2023, 12:01am UTC](https://integration.keap.com/t/how-to-connect-to-webhook/91350/1 "2023-09-07T00:01:04Z")

</div>

Hi there,  
I’m pretty new with webhook and apologize if my question sounds trivial.

I have read a post where it confirmed that KEAP offers REST Hook, and have head to the API documentation provided. I just would like to confirm the following thing. If I would like to retrieve data from KEAP API with an event-driven trigger, I would need to create a hook subscription and list the events that I would like to listen to, then to integrate it with my system, do I just connect to it the same way as how I would need to when connecting to KEAP API?

Thank you!

---

<div class="post-metadata">

**Author:** ![TomScott](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tomscott/32/67_2.png) [@TomScott](https://integration.keap.com/u/TomScott)\
**Post date:** [September 7, 2023, 6:24pm UTC](https://integration.keap.com/t/how-to-connect-to-webhook/91350/2 "2023-09-07T18:24:25Z")

</div>

Good morning Michellia!

The resthook subscription is an outbound call from our service to yours, so you’ll have to set up an endpoint to receive the calls on a publicly-available server and process them. If you request a subscription for “contact.edit”, then each time a Contact record is changed you will get a payload at your endpoint that provides the id of the affected Contact, which you could then use to make further calls to retrieve the changed record.

Thanks,

- Tom Scott  
Keap API Engineer

---

<div class="post-metadata">

**Author:** ![Michellia\_Herman](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@Michellia\_Herman](https://integration.keap.com/u/Michellia_Herman)\
**Post date:** [September 7, 2023, 10:13pm UTC](https://integration.keap.com/t/how-to-connect-to-webhook/91350/3 "2023-09-07T22:13:37Z")

</div>

Hi, thank you very much for the reply and explanation!  
I would also like to know if there’s any sample code or instruction on how to set up resthook on my end? I am using CakePHP/PHP

---

<div class="post-metadata">

**Author:** ![TomScott](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tomscott/32/67_2.png) [@TomScott](https://integration.keap.com/u/TomScott)\
**Post date:** [September 8, 2023, 4:23pm UTC](https://integration.keap.com/t/how-to-connect-to-webhook/91350/4 "2023-09-08T16:23:32Z")

</div>

I unfortunately don’t use PHP much myself, but we have a small Node Express script that we run internally when testing them that illustrates how it works:

```javascript
const express = require('express')

const app = express()

app.post('/listener', function(req, res) {
  var secret = req.header('X-Hook-Secret')
  if (secret) {
    // If this is the initial "verification" request containing a hook secret, capture and reply with it to validate
    console.log("X-Hook-Secret: " + secret)

    res.header('X-Hook-Secret', secret)
    res.send(JSON.stringify({}))
  } else {
    // Otherwise you've just received a payload for an event, so do something with it
    
    var timestamp = new Date()
    var hook = JSON.stringify(req.body, null, 2)
    console.log(`${timestamp}\n${hook}\n`)
    res.end()
  }
})

app.listen(8080, function() {
  console.log(`Listening for rest hooks on port 8080!`)
})

```

Note that you would have to deploy something like this somewhere to be able to make the subscription with a valid URL; our service can’t resolve your localhost.
