Sending the JSON object created by the form to my own custom RESTful API

  • matthew.mcguff85
    Asked on April 22, 2019 at 3:20 PM

    I wanted to know if its possible for me to configure an endpoint for my jot form to send data to. I know Zapier sort of does this but I would rather have it hit my own endpoint without having to go through Zapier.  Is there a way to do this?  Thanks in Advance.  I also am wanting to use the response to a name question to populate questions after it in a multi page form.  I have this sort of working but would like it to work better as its not working super well at the moment.  Feel free to call me.  Needing to get this working in the next 48 hours if possible.  Thanks! 

  • Alan_D
    Replied on April 22, 2019 at 4:30 PM

    For the first question, JotForm is not directly sending the submission data as a JSON object. But you can try our APIs. Please refer to this article for more information.
    API Documentation
    Get Submissions

    Secondly, you have used the field's unique name. This is returning the field value.Sending the JSON object created by the form to my own custom RESTful API Image 10You can also pass the values between other fields. Please refer to this article.
    How to Pass Field Value to Another Field?

    Unfortunately, we do not have phone support. Please contact us when you need.

  • matthew.mcguff85
    Replied on April 23, 2019 at 6:14 AM

    So I was looking at the api docs and setup and webhook event listener.  Basically what I am needing is the ability to return something containing the contents of the event to my site as I will display a custom message to the users that visit our site based upon what zip code they enter in their jotform.  So I created the webhook and registered my heroku app as event listener and got the following:

     curl -X POST -d "webhookURL=https://jot-form-webhook-listener.herokuapp.com/" -d "apiKey=46b2837e33f9e380fa27c6b1d51c7a6e" "http://api.jotform.com/v1/form/91043535669159/webhooks"

    {"responseCode":200,"message":"success","content":{"0":"https:\/\/jot-form-webhook-listener.herokuapp.com\/"},"duration":"14ms","limit-left":999}%


    However instead of getting a 200 response like I would expect from event submissions I am getting a "Service interrupted error" of 503.  See my log from my event listener I setup below: 


    2019-04-23T09:59:21.047259+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/" host=jot-form-webhook-listener.herokuapp.com request_id=912b9e23-962a-48f4-9d84-c35e9a5ff2ce fwd="104.154.27.150" dyno=web.1 connect=1ms service=31ms status=503 bytes=207 protocol=https

    2019-04-23T09:59:21.017354+00:00 app[web.1]: {}


    I am using node.js express for my event listener. Not super fancy at the moment, just trying to validate that this will work with the following:

    const express = require('express');
    const bodyParser = require('body-parser');

    const app = express();
    app.use(bodyParser.json());

    app.post('/', async (req, res) => {
    const payload = await req.body;
    console.log(payload);
    res.json(payload);
    });

    const port = process.env.PORT || 3001;
    app.listen(port, () => console.log(`Listening on port ${port}...`));

    Any ideas on what I need to be doing differently in order for the events to trigger correctly?  

  • jonathan
    Replied on April 23, 2019 at 7:44 AM

    Can you please try first also to debug your webhook request.

    To debug a webhook request e.g. form field names & its sample data, you can use RequestBin. Simply create a requestbin URL and set it as your form Webhook (as seen in the screenshot above). Make a sample submission to your form and requestbin will automatically collect the data and print it in a human-friendly way. 
     
    Sending the JSON object created by the form to my own custom RESTful API Image 1 Screenshot 30
     Example:
    Sending the JSON object created by the form to my own custom RESTful API Image 2 Screenshot 41

    How to Setup a Webhook with JotForm

    Also, for concerns about API, we have a dedicated team that you can directly contact, please send them an email in this address api@jotform.com.

    I hope this help. Let us know if you need further assistance.