Skip to main content

Let Zapier, Make or a CRM call your add-on

Free Advanced

The inbound half of Send your add-on’s own events through Benecaster’s webhook: an outside service tells your add-on something happened, through one Benecaster endpoint, POST /wp-json/benecaster/v1/actions. Benecaster signs the caller in (a WordPress Application Password for a user with the Benecaster Integration role), checks your add-on is active on the show, checks and coerces the fields, de-duplicates retries by idempotency key, rate-limits and logs the call. Your handler, registered with benecaster_register_integration_action(), only does the work. Setting up the caller’s side is on the Integration Setup page.

The caller posts { "action": "my-addon.booking.paid", "show_id": 12, "idempotency_key": "<the zap run id>", "data": { "booking_id": 381, "invoice_id": "INV-9" } } with HTTP Basic authentication (username + Application Password) and gets { "action", "show_id", "call_id", "replayed": false, "result": { … } }. A repeat with the same idempotency_key within 24 hours returns the first answer with "replayed": true and never calls your handler twice.

Code

<?php
add_action( 'benecaster_boot', function ( \Benecaster\Container $container ) {
    benecaster_register_addon( 'my-addon', static function (): void {
        benecaster_register_integration_action( 'my-addon', 'my-addon.booking.paid', [
            'label'   => __( 'A booking was paid elsewhere', 'my-addon' ),
            'fields'  => [
                'booking_id' => [ 'type' => 'integer', 'required' => true, 'description' => 'From my-addon.booking.confirmed' ],
                'invoice_id' => [ 'type' => 'string', 'required' => true ],
            ],
            'handler' => static function ( array $data, int $show_id, int $user_id ): array|\WP_Error {
                $booking = get_post( $data['booking_id'] ); // already an int, even if Zapier sent "381"
                if ( ! $booking || (int) get_post_meta( $booking->ID, '_show_id', true ) !== $show_id ) {
                    return new \WP_Error( 'unknown_booking', __( 'No such booking on this show.', 'my-addon' ), [ 'status' => 404 ] );
                }
                update_post_meta( $booking->ID, '_invoice_id', $data['invoice_id'] );
                return [ 'booking_id' => $booking->ID, 'status' => 'paid' ]; // ids, not personal data
            },
        ] );
    } );
} );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →