Iāve been using it on all versions of PHP since 7.1 up to 8.1 without any issues. Here are some key tips:
Turn on logging in Gravity Forms, Iāve setup a number of Webhooks with different systems with it and this info is super helpful for troubleshooting.
Hereās from my personal notes, itās been a while since I set this up, so my memory is a little fuzzy:
Getting and updating the access token
Gravity forms needs to get the access token from SuiteCRM first, then use the access token to connect to SuiteCRM to update, get, and add records.
You need to add a function to WordPressās functions.php to be able to do this:
You need to enter the appropriate client_id, client_secret. The grant type is āclient_credentialsā make sure you create this grant type in SuiteCRM Oath2
Note the _1 means this applies to form id 1
/*****add gf forms webhooks header for suitecrm**********/
add_filter( 'gform_webhooks_request_headers_1', function ( $request_headers ) {
$token = GFCache::get( 'suitecrm_token' );
if ( ! $token ) {
$post_url = 'https://xxxxxxxxxxxxxxxxxxxxxxxxx/Api/access_token';
$body = json_encode(array(
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'client_secret' => 'GravityForms',
'grant_type' => 'client_credentials',
));
$headers = array( 'Content-Type' => 'application/vnd.api+json',
'Accept' => 'application/vnd.api+json',
);
$response = wp_remote_post( $post_url, array( 'body' => $body, 'headers' => $headers ) );
gf_webhooks()->log_debug( 'gform_webhooks_request_headers: response => ' . print_r( $response, true ) );
if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) == 200 ) {
$response_body_json = wp_remote_retrieve_body( $response );
$response_body_array = json_decode( $response_body_json, true );
if ( isset( $response_body_array['access_token'] ) ) {
$token = $response_body_array['access_token'];
GFCache::set( 'suitecrm_token', $token, true, $response_body_array['expires_in'] - 30 );
}
}
}
if ( $token ) {
gf_webhooks()->log_debug( 'gform_webhooks_request_headers: token added.' );
$request_headers['Authorization'] = 'Bearer ' . $token;
$request_headers['grant_type'] = 'client_credentials';
}
return $request_headers;
} );
Modify the Output
Now that you have the access credentials in the header, you have to modify the output to be in a format accepted by SuiteCRM. You can add a function where the _1 is the form it applies to.
/****GF Webhook for SuiteCRM****/
add_filter( 'gform_webhooks_request_data_1', 'modify_suite_data', 50, 4 );
function modify_suite_data( $request_data, $feed, $entry, $form ){
$request_data = array(
'data' => array(
'type' => 'Leads',
'attributes' => array(
'name' => 'new lead',
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'email1' => rgar( $entry, '2' ),
'account_name' => rgar( $entry, '4' ),
)
)
);
gf_webhooks()->log_debug( 'request modified' );
return $request_data;
}