Jump to content

Developer Documentation

Webhooks

Webhooks allow your IPS community to communicate with third-party applications and websites.

Unlike like the REST API where the data are pulled from your community by 3rd party services, webhooks will notify the other service immediately once the defined event occurred.

1. Firing a Webhook

You can use the \IPS\Api\Webhook::fire() method to trigger the webhook in your code.

This method accepts 3 parameters, where only the first one is mandatory.

	/**
	 * This method will log the webhook to be fired, it's going to be fired via a task!
	 *
	 * @param	string	$event		The event key
	 * @param	mixed	$data		Data
	 * @param	array	$filters		Filters
	 * @return	void
	 */
	public static function fire( $event, $data = NULL, $filters = array() )

 

So to fire a simple hook, you'll call:

\IPS\Api\Webhook::fire( 'eventName', $payload );

This will register the webhook to the queue and it will be sent automatically with some minor delay ( something to keep in mind while testing your code!)

 

2. Registering the Webhook

The Application::getWebhooks() method can be used to make IPS Community Suite aware of the available webhooks.

The method has to return an array containing the available webhook keys and their payload.

	/**
	 * Returns a list of all existing webhooks and their payload in this app.
	 *
	 * @return array
	 */
	public function getWebhooks() : array
	{
		return array_merge( [
			'myApp_eventKey1' => \IPS\gallery\Album::class,
			'myApp_eventKey2' => ['test' => "array", 'member' => \IPS\Member::class]
		],parent::getWebhooks());
	}

Additional to implementing the getWebhooks method, you'll also need to create language strings with following key pattern: webhook_myApp_eventKey1 which will be used for the description in the webhooks form!

 

Edited by Daniel F

  Report Document


×
×
  • Create New...