Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Trigger hook on form submission, send to external API #2

Open
franzos opened this issue Apr 25, 2017 · 2 comments
Open

[Question] Trigger hook on form submission, send to external API #2

franzos opened this issue Apr 25, 2017 · 2 comments

Comments

@franzos
Copy link

franzos commented Apr 25, 2017

I'm trying to set-up a hook, that triggers once a specific form has received a new submission. The goal is, to post the submitted data to an external API. Here's what I have so far:

<?php
$service_url = 'https://api.insight.ly/v2.2/Leads';
$ch = curl_init($service_url);

curl_setopt($ch,
CURLOPT_HTTPHEADER,
array('Content-Type: application/json',
'Authorization: Basic ' . base64_encode('1234')));

curl_close($process);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPPOST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

$data = '{
  "FIRST_NAME": $first_name,
  "LAST_NAME": $last_name,
  "MOBILE_PHONE_NUMBER": $mobile_phone_number,
  "EMAIL_ADDRESS": $email_address,
  "ADDRESS_STREET": $address_street,
  "ADDRESS_CITY": "$address_city,
  "ADDRESS_COUNTRY": $address_country,
  "LEAD_STATUS_ID": 1234,
  "LEAD_SOURCE_ID": 1234,
  "LEAD_DESCRIPTION": $comments,
  "LEAD_RATING": 2,
  "RESPONSIBLE_USER_ID": 1234,
}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return = curl_exec($ch);
$err = curl_errno($ch);
$msg = curl_error($ch);

error_log($return);

echo $return;

curl_close($ch);
?>

I hope you could advice me on which code hook to use and whether I have populated the placeholders correctly e.g. $first_name. Once I get this up and running, I'll write up a short guide for others!

PS: Cheers to the new website 👍

@franzos franzos changed the title [Question] [Question] Trigger hook on form submission, send to external API Apr 25, 2017
@benkeen
Copy link
Member

benkeen commented Oct 14, 2017

Hey @franzos, gah I'm so sorry I missed your question here. Did you end up getting this sorted?

@brunt82
Copy link

brunt82 commented Jun 24, 2024

Hi,

I had the same idea and was looking for an answer: Which hook can I use to send a PHP request to an external API when adding a new submission?

It seems that all three "updateSubmission" hooks are already triggered on the review page. However, the files have not yet been uploaded there, which means they cannot be passed on to the API.

Any ideas?

Thanks and regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants