Webhook Send Admin Field Label [RESOLVED]

Hi,

Is there a way to have a webhook send the Admin Field Label instead of the field ID by default? I have a form with over 30 fields and it would be nice if I didn’t have to map each one.

This should swap the keys from field IDs to admin labels when performing a webhook request. You’ll want to update the check for SpecificWebService or replace with a check on your specific feed ID.

// Replace keys w/ admin labels when running webhook request
add_filter( 'gform_webhooks_request_data', function( $request_data, $feed, $entry, $form ) {

	if (
		rgars( $feed, 'meta/requestBodyType' ) === 'all_fields'
		&& strpos( rgars( $feed, 'meta/requestURL' ), 'SpecificWebService' ) !== false
		 ) {
             
		gf_webhooks()->log_debug( 'gform_webhooks_request_data: replacing keys with admin labels.' );

		foreach( $form['fields'] as $item ) {

			if ( $item->adminLabel != '' ) {

				if( isset( $item->inputs ) && is_array( $item->inputs ) ){
					foreach ( $item->inputs as $input ){
						$request_data[ $item->adminLabel . '-' . $input['label'] ] = rgar( $entry, $input['id'] );
						unset( $request_data[ $input['id'] ] );
					}
				} else {
					$request_data[ $item->adminLabel ] = rgar( $entry, $item->id );
					unset( $request_data[ $item->id ] );
				}

			} elseif ( $item->type == 'hidden' ) {

                $request_data[ $item->label ] = rgar( $entry, $item->id );
                unset( $request_data[ $item->id ] );

            }

		}

	}

	return $request_data;

}, 10, 4 );
1 Like

this-up

1 Like

I was hoping I was missing a feature that let me toggle a setting, but since there doesn’t appear to be one, I appreciate the code to handle this.

1 Like