Connect Webhook to an API hosted on a local server

  • jkelly123email
    Asked on April 11, 2024 at 12:59 PM

    I need someone to go over webhooks with me and help to connect to an API hosted on a local server.

  • Mikhail JotForm Support
    Replied on April 11, 2024 at 1:16 PM

    Hi Jack,

    Thanks for reaching out to Jotform Support. Webhook allows you to automatically send your form data to your endpoint or other apps. You can Integrate Webhooks Into Your Form. It's easy to do. Let me show you how:

    1. In Form Builder, click on Settings in the orange navigation bar at the top of your screen.
    2. In the menu on the left side of your screen, click on Integrations.
    3. Click on Webhooks. Connect Webhook to an API hosted on a local server Image 1 Screenshot 30
    4. Enter the URL into the box below Add WebHook to send submission notifications.
    5. Click on Complete Integration. That's it. Connect Webhook to an API hosted on a local server Image 2 Screenshot 41

    You may also want to check out API Document and Webhook PHP Script Examples.

    Give it a try and let us know if you have any other questions.

  • owlypia
    Replied on April 11, 2024 at 3:37 PM

    Hi Mikhail,

    I did completely as you show. no data inserting to the table after submission.

    Can you find the problem?

    Form: https://form.jotform.com/241015946684966

    you can test the form with free coupon code: kenan

    php code:

    URL : https://open.owlypia.org/jotforms/local.php

    <?php

    $servername = "localhost";

    $username = "open_login";

    $password = "xxxxxxxxx";

    $dbname = "open_login";

    $dbtable = "jotform";

    // Create connection

    $mysqli = new mysqli($servername, $username, $password, $dbname);

    // Check connection

    if ($mysqli->connect_error) {

    die("Connection failed: " . $mysqli->connect_error);

    }

    // Get field values from the form

    // Get unique submissionID - nothing to change here

    $sid = $mysqli->real_escape_string($_REQUEST["submissionID"]);

    // Get form field values and decode - nothing to change here

    $fieldvalues = $_REQUEST["rawRequest"];

    $obj = json_decode($fieldvalues, true);

    // Replace the field names from your form here

    $fullname = $mysqli->real_escape_string($obj["fullname"]);

    $gender = $mysqli->real_escape_string($obj["gender"]);

    $email = $mysqli->real_escape_string($obj["email"]);

    $fsubject = $mysqli->real_escape_string($obj["fsubject"]);

    $teamname = $mysqli->real_escape_string($obj["teamname"]);

    $schoolname = $mysqli->real_escape_string($obj["schoolname"]);

    $result = $mysqli->query("SELECT * FROM $dbtable WHERE id = '$sid'");

    // If submission ID exists, update the record...

    if ($result->num_rows > 0) {

    $result = $mysqli->query(

    "UPDATE $dbtable SET fullname = '$fullname', gender = '$gender', email = '$email', fsubject = '$fsubject', teamname = '$teamname', schoolname = '$schoolname' WHERE id = '$sid'"

    );

    echo "Existing Record Updated!";

    }

    // else, insert record

    else {

    $result = $mysqli->query(

    "INSERT IGNORE INTO $dbtable (id, fullname, gender, email, fsubject,teamname,schoolname) VALUES ('$sid', '$fullname', '$gender','$email','$fsubject','$teamname','$schoolname')"

    );

    echo "New Record Added!";

    if ($result === false) {

    echo "SQL error:" . $mysqli->error;

    }

    }

    $mysqli->close();

    ?>



  • Neil JotForm Support
    Replied on April 11, 2024 at 4:24 PM

    Hi Jack,

    Thanks for getting back to us. I’ll need a bit of time to look into this. I’ll get back to you as soon as I can.

    In the meantime, let us know if you have any other questions.

  • Neil JotForm Support
    Replied on April 11, 2024 at 5:27 PM

    Hi Jack,

    Thanks for patiently waiting. I cloned and tested your form to see if I could replicate the issue, but everything is working as it should. I was able to get to capture the data. Check out my screenshot below:

    Connect Webhook to an API hosted on a local server Image 1 Screenshot 20

    I also asked our backend team to take a look at your code, and they've said it looks correct, but you have to debug your code to find the possible issue. It would help if you could also get assistance from your developer team about this.

    If the issue persists, let us know, and we'll investigate it more to see if we can figure out what's going on.

    Keep us updated and let us know if you need more help.

  • owlypia
    Replied on April 11, 2024 at 5:48 PM

    Hi,

    Instead of using Webhook, if we use Thank you page, it works. But I need thank you page to redirect to other page. Many time I tried to make it with only Webhook, it does not insert the data to the mysql table, even I used jotform own code.

    Connect Webhook to an API hosted on a local server Image 1 Screenshot 20

  • Sonnyfer JotForm Support
    Replied on April 11, 2024 at 9:08 PM

    Hi Jack,

    I'm very sorry to hear that. Can you share the error message that you see when you use Jotform sample code? As we're unable to replicate the issue on our end, it's best if you can reach out to your developer to adjust your existing code to send form data yo your MySQL Database. You can also hire an expert from our Partners Page or through Fiverr to help you with it.

    Thanks for your patience and understanding, we appreciate it.

  • owlypia
    Replied on April 12, 2024 at 6:32 AM

    Hi,

    I need your developer to check the the following video, I want to know where is the mistake?

    https://drive.google.com/file/d/1aLwM2pQjIpAZogudf-Cd8F39UDTGXDZ2/view?usp=sharing


    https://open.owlypia.org/jotforms/local.php

    <?php

    $password = "xxxx";

    $servername = "localhost";

    $username = "open_login";

    $dbname = "open_login";

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {

     die("Bağlantı hatası: " . $conn->connect_error);

    }

    $fullname = $_POST['fullname'];

    $sql = "INSERT INTO jotform (fullname) VALUES ('$fullname')";

    if ($conn->query($sql) === TRUE) {

     echo "Addedd";

    } else {

     echo "Error: " . $sql . "<br>" . $conn->error;

    }

    $conn->close();

    ?>

  • Mikhail JotForm Support
    Replied on April 12, 2024 at 7:19 AM

    Hi Jack,

    Thanks for getting back to us. I also cloned your form and tested it to see if I could replicate the issue, but everything was working properly. I was able to get the data using the webhook.site. Check out the screencast below to see my results:

    Connect Webhook to an API hosted on a local server Image 1 Screenshot 20

    Like my colleague said in this reply, you can reach out to your developer to see and debug your code to be able to send it to your MySQL database. If you don't have one, you're welcome to work with a third party who may be able to help you. You can check out our Jotform Solutions Partner Directory for a list of consultants who've asked to be included. You can also check out Jotform and Fiverr partnership page.

    You can get in touch with the right Solutions Partner for you by sorting them by location, type of service, industry, language support, or partner tier. Just fill out the contact form for the Jotform partner you'd like to work with, so they can make the necessary preparations to help you.

    Keep in mind, though, that these parties operate independently of Jotform, so we assume no responsibility or liability for their work or their actions. 

    We hope you find the help you're looking for.

  • owlypia
    Replied on April 12, 2024 at 7:23 AM

    Hi

    Can you show me THANK YOU page setting on your example.

    thanks

  • Lorenz JotForm Support
    Replied on April 12, 2024 at 8:34 AM

    Hi Jack,

    Thanks for reaching out to Jotform Support. Based on my colleague's screencast, it appears like he's using a webhook endpoint. Currently, below is the PHP script you're using as webhook, right?

    <?php
    $password = "xxxx";
    $servername = "localhost";
    $username = "open_login";
    $dbname = "open_login";
    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
     die("Bağlantı hatası: " . $conn->connect_error);
    }

    $fullname = $_POST['fullname'];
    $sql = "INSERT INTO jotform (fullname) VALUES ('$fullname')";

    if ($conn->query($sql) === TRUE) {
     echo "Addedd";

    } else {
     echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?>


    You're missing the part where you need to get the raw request data and decode. Could you try the code below instead:

    <?php
    $password = "xxxx";
    $servername = "localhost";
    $username = "open_login";
    $dbname = "open_login";
    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
     die("Bağlantı hatası: " . $conn->connect_error);
    }

    $fieldvalues = $_REQUEST["rawRequest"];
    $obj = json_decode($fieldvalues, true);

    //this depends on the unique name of the input field on browser inspect
    $fullname= $obj['q59_fullname'];

    $sql = "INSERT INTO jotform (fullname) VALUES ('$fullname')";

    if ($conn->query($sql) === TRUE) {
     echo "Addedd";

    } else {
     echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?>


    Give it a try and let us know how it goes.

  • owlypia
    Replied on April 12, 2024 at 8:48 AM

    Hi,

    It works, thank you very much. now I got the point.

    Thank you

  • owlypia
    Replied on April 12, 2024 at 12:41 PM

    Hi,

    I did not find the name of a stripe product like "q59_fullname" on the form.


    Can you find it on https://form.jotform.com/241023822915955 ?

    Thanks

  • Sidharth JotForm Support
    Replied on April 12, 2024 at 1:25 PM

    Hi Jack,

    Thanks for getting back to us. I checked your form and found that the Stripe element's unique name is {payment}. You can easily locate the unique name and field IDs of the Stripe payment field. Let me show you how:

    1. In Form Builder, click on the Stripe Payment element and then click on the Gear Icon.
    2. In the Advanced tab, click on the Field Details accordion to see the unique name and field IDs. Connect Webhook to an API hosted on a local server Image 1 Screenshot 20

    Reach out again if you have any other questions.

  • owlypia
    Replied on April 12, 2024 at 1:48 PM

    I mean unique name of the input field on browser inspect.

    for example:

    on jotform: gender 

    on browser inspect: q34_gender

  • Sidharth JotForm Support
    Replied on April 12, 2024 at 2:30 PM

    Hi Jack,

    Thanks for getting back to us. Do you want to know the unique name of the input elements of the Stripe payment? You can inspect element to know the unique name:

    Connect Webhook to an API hosted on a local server Image 1 Screenshot 20

    Please note that the input elements of the Stripe payment may not be accessible in the response data, as they are not a part of the form elements. These fields are loaded directly from Stripe via an iframe. You can directly read the payment field to retrieve the complete transaction details.

    Reach out again if you have any other questions.

  • owlypia
    Replied on April 12, 2024 at 2:34 PM

    Thank you very much.

  • owlypia
    Replied on April 19, 2024 at 5:57 PM

    Hi again,

    Is it possible to get CUS_ code ( sample: cus_KavIYQCwAxm8US) from stripe transaction?

    Thanks

  • Mike_G JotForm Support
    Replied on April 19, 2024 at 10:07 PM

    Hi Jack,

    Thanks for getting back to us. I’ll need a bit of time to look into this. I’ll get back to you as soon as I can.

    In the meantime, let us know if you have any other questions.

  • Mike_G JotForm Support
    Replied on April 20, 2024 at 5:19 PM

    Hi Jack,

    Thanks for your patience and understanding, we appreciate it. In your existing script, you can append this:

    $custID = $mysqli->real_escape_string($obj["myProducts"]["customerid"]);

    Note: myProducts is your Stripe payment field's field name as you see in the screenshot below:

    Connect Webhook to an API hosted on a local server Image 1 Screenshot 20

    After that, add the $custID variable to your UPDATE and INSERT functions. And that's it.

    Give it a try and let us know if you have any other questions.

 
Your Answer