Webhooks Add-On Using Two Feeds [RESOLVED]

I am using the gform_webhooks_request_data filter and I need to specify the form’s feed so my filters look like this:

Form 1, feed 1

add_filter( 'gform_webhooks_request_data_1_1', 'customize_webhook_request_data_leads', 10, 3 );

Form 1, feed 2

add_filter( 'gform_webhooks_request_data_1_2', 'customize_webhook_request_data_files', 10, 3 );

However, I am getting the response Invalid XML document.

Removing the feed number returns successful.

add_filter( 'gform_webhooks_request_data_1', 'customize_webhook_request_data_leads', 10, 3 );

Am using the filter incorrectly or if it is likely a problem with my code?

My working code looks like this:

function customize_webhook_request_data_leads( $request_data, $feed, $entry ) {

    // Extract data from the entry
    $firstName = rgar( $entry, '9' );
    $lastName = rgar( $entry, '10' );
    $phoneNumber = rgar( $entry, '17' );
    $email = rgar( $entry, '16' );
    $state = rgar( $entry, '23' );
    $description = rgar( $entry, '5' );
    $addTimeStamp = date('c');

    // Construct the XML data
    $xml_data = new SimpleXMLElement('<lead/>');
    $xml_data->addAttribute('token', '123abc');
    $xml_data->addAttribute('test', '1');
    $xml_data->addChild('firstName', $firstName);
    $xml_data->addChild('lastName', $lastName);
    $xml_data->addChild('phoneNumber', $phoneNumber);
    $xml_data->addChild('email', $email);
    $xml_data->addChild('state', $state);
    $xml_data->addChild('description', $description);
    $xml_data->addChild('addTimeStamp', $addTimeStamp);    

    // Return XML as a string
    return $xml_data->asXML();
}

add_filter( 'gform_webhooks_request_headers_1', 'set_webhook_request_headers_leads', 10, 3 );
function set_webhook_request_headers_leads( $headers, $feed, $entry ) {
    $headers['Content-Type'] = 'application/xml';
    return $headers;
}

Appending the feed ID to the filter name is not supported. If you want to limit the scope of a function to a specific feed, you’ll need to test the feed ID within the function, e.g.

if ( rgar( $feed, 'id' ) != 1 ) {
    return $request_data;
}
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.