Skip to main content

Create a Helpshift Ticket via Gravity Forms

June 7th, 2019

Gravity Forms is one of my favorite plugins to work with as it has a lot of really well-documented functions… plus, I hate hand-coding forms. One of the best utility functions is one that happens after form submission that can be used to integrate with various third party APIs using the submitted form data: gform_after_submission.

Recently, I had a project where I need a custom built Gravity Form to integrate with Helpshift, creating a support ticket on form submission. Within the functions.php file of the theme, I set up a function to do this that looked like this:

<?php
// this is targeting form #1, change this or remove to target all forms
add_action( 'gform_after_submission_1', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {

$post_url = 'https://api.helpshift.com/v1/PUT-YOUR-HELPSHIFT-ID-HERE/issues';

// let's say your name field is field 1 of the form
$name = rgar( $entry, '1' );

// let's say email field is field 2 of the form
$email = rgar( $entry, '2' );

// let's say issue field is field 3 of the form
$issue = rgar( $entry, '3' );

// we will create an array of this data to send via the API
$body = array(
'email' => $email,
'message-body' => $issue,
'author-name' => $name,
);

// Uncomment the below line to debug, if necessary
//GFCommon::log_debug( 'gform_after_submission: body => ' . print_r( $body, true ) );

// Helpshift requires an API key that needs write access
$headers = array('Authorization' => 'Basic PUT-YOUR-HELPSHIFT-API-KEY-HERE');

$request = new WP_Http();
$response = $request->post( $post_url, array( 'headers' => $headers, 'body' => $body ) );

// Uncomment below line to debug, if necessary
//GFCommon::log_debug( 'gform_after_submission: response => ' . print_r( $response, true ) );
} ?>

Be sure to plug in your specific Helpshift data in the all caps noted areas above. You can add additional fields in the body based on what you want to send using other fields available when creating new issues in Helpshift. The Helpshift API is fairly well-documented and you can reference that here.

MORE: WordPress Tutorials

Related Articles