Fetch webhook response headers

I’m using the Gravity Forms Webhook addon to send form details to a third-party endpoint. The API will send back a response and depending on a value in the response header I’d like to show a message to a user. I’m looking for the following:

Confirmation if this function is the right function to use gfrom_webhooks_post_request to get the response? How I should go about getting the headers in the response?

Thank you

So they don’t impact form submission performance, most add-on feeds, including webhooks, are processed via a separate background request. For this reason, the webhook response is not available out of the box when the form confirmation is displayed to the submitter.

You could use the gform_is_feed_asynchronous filter to disable background processing for the add-on, so its feeds will be processed before the confirmation is displayed.

The gfrom_webhooks_post_request hook is the correct hook to use to access the webhook response headers. You can do that like so:

$headers = wp_remote_retrieve_headers( $response );
gf_webhooks()->log_debug( 'gform_webhooks_post_request: headers => ' . print_r( $headers, true ) );

If you want to display values from the response headers on the confirmation, you’ll need to stash them somewhere that can also accessed when the confirmation is being prepared. You could save them as custom entry meta, e.g.

gform_update_meta( rgar( $entry, 'id' ), 'webhook_headers', $headers );

You would then be able to access that when using the gform_confirmation filter to customize the confirmation message.

$headers = gform_get_meta( rgar( $entry, 'id' ), 'webhook_headers' );