API Connection Error (GravityForms)

Hi,

I am attempting to use Gravity Forms Webhooks Add-on to create leads and opportunities in SuiteCRM. Here are the available settings Webhooks has available (imgur link). It appears to connect and authenticate, but I get this error:

[sslverify] => 1 ) 2020-10-21 6:56:34.037528 - DEBUG --> GF_Webhooks::process_feed(): Webhook successfully executed. code: 400; body: { "errors": { "status": 400, "title": null, "detail": "The options \"email\", \"name\", \"type\" do not exist. Defined options are: \"data\"." } } 2020-10-21 6:56:34.037600 - DEBUG --> GF_Feed_Processor::task(): Marking entry #78 as fulfilled for gravityformswebhooks

Any help would be great!

Thanks

Karen

Hi,
please try “email1” instead:

{
  "data": {
    "type": "Contacts",
    "attributes": {
      "last_name": "someLastName",
      "email1" : "test@testing.org"
    }
  }
}

Hey @diligent,

Thanks for the fast reply.

I tried changing email to email1 and got the same error.

Is this error because webhooks uses “Body” and suiteCRM is looking for “Data”?

Thanks

Karen

Hi,
I assume the json that is being created just doesnt match the expected format. Do you have a possibility to design the json structure yourself?

Hi @diligent,

Thanks for another fast reply!

No, the WordPress Webhooks plugin I’m using doesn’t have that option. I could have it customized but I’m hoping for an easier solution. I was pondering trying “Webtolead”, it’s a module in the SuiteCRM store, but it doesn’t have any reviews.

Thanks

Karen

Hey, if you’re just trying to push form fills to a lead or contact, I use 3rd Party Integration plugin. It works for Gravity Forms and Contact Form 7. I wrote a tutorial on my blog, it’s for Contact Form 7, but works pretty much the same for Gravity Forms. Plus, it’s a free Plugin that works with WordPress.

https://igosalesandmarketing.com/how-to-integrate-suitecrm-and-contact-form-7/

1 Like

Karen I’m almost there… @diligent in gravity forms webhooks you can design the output. With…

add_filter( ‘gform_webhooks_request_data_1’, ‘modify_data’, 10, 4 );
function modify_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’ ),
)
)
);
return $request_data;
}

Note: _1 in the filter limits to form id:1
The 1.3, 1.6, etc are the field ID’s from the form.

The output is:

[body] => {“data”:{“type”:“Leads”,“attributes”:{“name”:“new lead",“first_name”:“Paultest”,“last_name”:“testing”,“email1”:"pablotest@testing.com”,“account_name”:“my company”}}}

It all looks right to me but I’m getting, "code: 401; body: {“error”:“access_denied”,“message”:“The resource owner or authorization server denied the request.”,“hint”:“Error while decoding to JSON”} "

I’ve tested the setup in postman and it works. Without the new JSON, it connects and gives me the error about the missing"/data:" . Anyone see anything wrong in the JSON output? Ideas?

Whoohoo! I’ve successfully used Gravity Forms Webhook Add on to create a lead from a Gravity Form. Presumably, I can now create/update any record from a Gravity Form. The key thing I was missing was the content type:

Once I added that header, the Gravity Forms function works to populate the data correctly!

1 Like

Hi Paul, is there a step by step tutorial out there to set up the using the webhooks plugin?

Hey @cammie57, none that I know of, I kind of pieced it together. I definitely want to make a walk-through how to video on it. One stumbling block is that my process is still overly complicated (even though it does work). The issue I have is the V8 Api needs an access token. Webhooks doesn’t generate an access token on connection, so I’m using Postman to initially connect and then create the access token. I use the access token in Webhooks to connect to suitecrm. This works… until the access token expires.

So in a production environment, I’d have to somehow hack the DB and make the token valid for like 5 years or something. If you want the instructions I have so far I’d be happy to send them to you.

This would be a great feature if I could get a simpler way to get it working. Presumably, you could create/update any record in SuiteCRM with Gravity Forms, fairly easily by using the Webhook plugin.

This has been kind of a side project of mine when I have a spare moment just because the potential is so great. With WordPress, Gravity Forms and SuiteCRM with a pretty easy way to integrate all 3 it would be awesome!

Here’s a PDF of my procedure (work in process) that I have so far.

production_api_webhooks_suitecrm_gravityforms [iGoWIKI].zip (163.2 KB)

Hi, @pstevens

Why you don’t use API V4.1?

I was really struggling with the V4.1 API. The V8 documentation was so much clearer. (I’m kind of a newbie to API’s). I also found a V8 Postman config file that I downloaded and was super helpful. I haven’t been able to connect via 4.1 yet. It would be great if I just needed a key to connect and use the V4.

Do you have any postman settings you can share to connect via V4.1 to say add a record. That would be super helpful!

If I can get that working, that’s way simpler to configure and I’ll definitely make a video for the community.

@pstevens

I am using SOAP for API V4.1. It’s very easy. Which problem are you have?

I’m struggling with what credentials to send to gain access and also what URL to use to add a new “lead” let’s say.

@pstevens
It’s working for me.

$location='https://example1.com/service/v4_1/soap.php?wsdl'
$login_parameters = array(
    "user_auth" => array(
        "user_name" => 'api_user',
        "password" => '01234567890123456789012345678901' //MD5 hash of password
    )
);
/* if using https without correct certificate */
$streamContext=stream_context_create([
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed'=>true
    ],
]);
$client = new SoapClient($location,array('stream_context'=>$streamContext));
$session = $this->client->__soapCall('login',$login_parameters);
$record=$this->client->__soapCall(
    'set_entry',array(
        $session->id,'Leads',array(
            array('name'=>'first_name','value'=>'name_1 name_2',
            array('name'=>'email1','value'=>'mail@example2.com',
            array('name'=>'phone_mobile','value'=>'+0123456789',
            array('name'=>'description','value'=>'text',
            array('name'=>'assigned_user_id','value'=>'01234567-0123-0123-0123-012345678901')
        )
    )
);
$client->__soapCall('logout',$session->id);

Thanks Dude, that’s super helpful! However my problem is that the plugin in question can only submit requests via JSON or FORM. I’m not sure if I can implement it like that with the plugin. With V8 I was able to use JSON to submit. (Again this API stuff is new to me).

Thank you! I subscribe to your youtube channel. You make very helpful videos! This API stuff is new to me, but I’m going to try to see what I can do with the info you posted. Looking forward to the video if you get to the bottom of this. Looks very promising!

I didn’t even use Gravity Forms Webhook Add on as I believe it has a fee.
I went into wp-content/themes/salient/fuctions.php. I use salient but use whatever is your current theme in WP.

Then I entered this:


add_action('gform_after_submission','post_to_third_party', 10, 2);

function post_to_third_party($entry, $form){


	//Log In
    $url = 'https://WEBSITE.COM/service/v4_1/rest.php';
    
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    // Set the POST arguments to pass to the Sugar server
    $parameters = array(
                        'user_auth' => array(
                        'user_name' => 'USERNAME',
                        'password' => md5('PASSWORD'),
                        ),
                      );

    $json = json_encode($parameters);

    $postArgs = array(
                      'method' => 'login',
                      'input_type' => 'JSON',
                      'response_type' => 'JSON',
                      'rest_data' => $json,
                    );

    curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);

    $response = curl_exec($curl);

    // Convert the result from JSON format to a PHP array
    $result = json_decode($response);

    if ( !is_object($result) ) {
        die("Error handling result.\n");
    }

    $session = $result->id;

	//Get data
	$parameters = array(
		'session' => $session,
		'module' => 'Leads',
		'name_value_list' => array (
				array('name' => 'survey_id_c',                'value' => 'XXXXX'),

				array('name' => 'primary_address_street',     'value' => rgar($entry,'3.1')),
				array('name' => 'primary_address_city',       'value' => rgar($entry,'3.3')),
				array('name' => 'primary_address_state',      'value' => rgar($entry,'3.4')),
				array('name' => 'primary_address_postalcode', 'value' => rgar($entry,'3.5')),
							
				array('name' => 'first_name',                 'value' => rgar($entry,'1.3')),
				array('name' => 'last_name',                  'value' => rgar($entry,'1.6')),
				array('name' => 'phone_work',                 'value' => rgar($entry,'2')),    
				array('name' => 'email1',                     'value' => rgar($entry,'4')),

				array('name' => 'qweb_01_c',                     'value' => rgar($entry,'9')),
				array('name' => 'qweb_02_c',                     'value' => rgar($entry,'7')),
				array('name' => 'qweb_03_c',                     'value' => rgar($entry,'10')),
				array('name' => 'qweb_04_c',                     'value' => rgar($entry,'6')),

			),
	);

	$json = json_encode($parameters);
    $postArgs = 'method=set_entry&input_type=JSON&response_type=JSON&rest_data=' . $json;
    
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
    
    $response = curl_exec($curl);
    $result = json_decode($response,true);    
    $recordId = $result['id'];

Nice @johnwreford Can’t wait to try that! I’ve been struggling to find an easy way to send Gravity Form fills into SuiteCRM. This looks even simpler than the webhooks plugin.