Skip to content

REST Hooks

Paride Azzari edited this page Aug 24, 2024 · 1 revision

This is one of the most important API features. Through this endpoint you can create and set up REST hooks for when a specific event occurs in your application.

What are REST Hooks?

REST Hooks itself is not a specification, it is a collection of patterns that treat webhooks like subscriptions. These subscriptions are manipulated via a REST API just like any other resource.

With most modern REST APIs, polling is the only way to detect changes. But it doesn't have to be. On average, 98.5% of polls are wasted. There is a better way. REST Hooks enable real-time communication and eliminate polling. -- RESTHooks.org

Infusionsoft offers a growing set of REST Hooks to keep you notified of changes in your data. To get started, use List Hook Event Types to discover event types. Event types are identified using noun.verb dot syntax, e.g.: contact.add or invoice.delete.

Once you've chosen the events you're interested in, subscribe to them via Create a Hook Subscription.

All the methods that return a Hook model will return an array with:

[
    'key' => string,
    'eventKey' => string,
    'hookUrl' => string,
    'status' => string,
]

Types

To list all available rest hooks run the following command:

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->types();

It will return an array of strings representing the key events that can be used to trigger a rest hook.

Create

To create a hook subscription run the following:

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->create(string $event_key, string $hook_url);

The event key can be taken from the previous command (Type), the second parameter is the url that will be used to execute the request.

To enable a hook you need to verify the Hook Subscription.

Verify

This operation is used to verify or reactivate a hook subscription.

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->verify(string $key);

List

This method returns a list of all the hooks subscriptions.

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->list();

It returns an array of all the hooks subscriptions, active or not.

Find

This method retrieves a specific hook.

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->find(string $key);

Update

To update a specific hook you can use the following method

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->update(string $key, string $event_key, string $hook_url);

Delete

This method delete a specific hook.

use KeapGeek\Keap\Facades\Keap;

Keap::hook()->delete(string $key);
Clone this wiki locally