I am working with Gravity Forms to send that form Data to an external API with a post request.
This is what I have so far. It is using the gform_after_submission and then using that information to send to the third party API with a cURL request.
add_action( 'gform_after_submission_1', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
$body = array(
'first_name' => rgar( $entry, '22' ),
'last_name' => rgar( $entry, '23' ),
'email' => rgar( $entry, '16' ),
'phone' => rgar( $entry, '18' ),
'streetadd' => rgar( $entry, '6' ),
'city' => rgar( $entry, '8' ),
'state' => rgar( $entry, '10' ),
'postalcode' => rgar( $entry, '19' ),
'dob' => rgar( $entry, '13' ),
'contact' => rgar( $entry, '14' ),
'product' => rgar( $entry, '1' ),
)
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'URL to my API',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS =>'{
"tenant": "07484e7f-b9b7-4d12-8c7e-3fa19d2e39a1",
"first_name": first_name,
"middle_initial": "L",
"last_name": last_name,
"origin": "Website",
"business_type": "Personal",
"business_name": "Acme Incorporated",
"country_code": "US",
"lob": "Home",
"payment_type": "Credit Card",
"lead_format": "json",
"data": {
"Version": "7.0",
"Proposer": {
"Business": false,
"Forename": first_name,
"Surname": last_name,
"DateOfBirth": dob
}
}
}
}',
CURLOPT_HTTPHEADER => array(
'X-API-Key: *APIKEY*',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}
When I go to test this, it isn’t sending over anything from the form to my API. I thought it was similar to the Javascript "get elementbyID and then referring to that like I did with the rgar here. However, nothing is sending over from my form and I am not able to see any error messages in my log. I appreciate any help I can get with this.