API and unique name fields.

  • aimee2
    Asked on January 7, 2022 at 6:05 PM

    Hi

    First thanks for a great tool. Second the api docs are really not so clear.

    In the docs i read: curl -X POST -d "submission[1]=answer of Question 1" -d "submission[2_first]=First Name" -d "submission[2_last]=Last Name" "https://api.jotform.com/form/{formID}/submissions?apiKey={apiKey}"

    And via other support tickets i had to find out that the fieldnames i see in the form editor or tables are actually not the field names i have to use, instead the docs state that i should find the field names via the source code of a form.

    Thats not really true as per example a field i have has a unique name vesselname and field id #input_25 if checked via form editor, but in the source i see this:

    <input type="text" id="input_21" name="q21_vesselname" data-type="input-textbox" class="form-textbox" data-defaultvalue="" style="width:310px" size="310" value="" data-component="textbox" aria-labelledby="label_21">

    When using label_21 no data is being submitted, but when i tested just 21, it worked.

    It took me 2 days to find out how to work correctly, and i think Jotform could update the docs to make this more clear, or use the unique name of the field, or perhaps at least expose the proper field to use when using the api.

    But anyway.. im on my way to create smth now so all good. However... i have a date field in my form, and whatever i try i cant get the date in via the api.

    How can i use this data field in submit a form via the api ?#day_22, #month_22, #year_22

    If i use 22 no data is accepted, if i use #day_22 also not.


    Can u teach me how to do it or point me to the right docs?


    Many thanks!


  • Amin JotForm Support
    Replied on January 8, 2022 at 12:53 AM

    Hi there,

    Thanks for reaching out to us!

    I think you're confusing the unique name with CSS ID. You can find fields' unique names following the guide below.

    How-to-find-field-ids-and-names

    Example:

    1641620590 61d9246e08dbb  Screenshot 10

    For the Date Picker, you can strip day, month and year as shown below.

    UniqueName:day
    UniqueName:month
    UniqueName:year

    Should you have any further inquiries, we will be more than happy to help.

  • aimee2
    Replied on January 8, 2022 at 1:42 AM

    I wish u where right!


    However ... when creating an API request to jotform, if i use the unique field name the request fails.

    When i use the question number, the api accepts the request and created the submission

  • Ahmed_S
    Replied on January 8, 2022 at 5:02 AM

    Greetings,

    It's preferred to perform a GET submission call to know the questions numbers and the properties of the form field, this way you can construct your POST or PUT calls with the correct question number and properties id/name for each field.

    In order to submit data to the Date Picker field you will use the question number of the field and assign the values to the date properties (day, month & year) as the following:

    In this example the question number of the date field is "5" and the date vlaue needed to be submitted is January 22, 2022.

    For POST call:

    curl -X POST -d "submission[5][day]=22" -d "submission[5][month]=01" -d "submission[5][year]=2022" "https://api.jotform.com/form/{formID}/submissions?apiKey={apiKey}"

    For PUT call you will send the submission data in the form of array of JSON objects

    curl -X PUT -d '[{"5":{"day":"24","month":"02","year":"2023"}}]' "https://api.jotform.com/form/{formID}/submissions?apiKey={apiKey}"


    Please let us know if you need further assistance, we are happy to help.

  • aimee2
    Replied on January 8, 2022 at 5:08 AM

    thanks ill try that!


    I noticed that after submission via API there is no notification email sent, so i dont receive the PDF file which i need for printing.

    So i contructed a request in the webhooks module of zapier


    https://eu.jotform.com/API/pdf-editor/pdf-converter/220032571796051/fill-pdf?download=1&submissionID=5174073294811277916&type=PDFv2&apikey=1604a7e2261dfbbcbf0a91a6988b98d6


    It seems to go true bit i get Cross-Site Requests not allowed!
    seems logic, if i get Enterprise, can i use this or is there a better way to get the pdf after submission?

    As its automated i cant login to browser to download them.

  • Amin JotForm Support
    Replied on January 8, 2022 at 5:16 AM

    Please use the below API endpoint instead to bypass the CORS error.

    https://eu-api.jotform.com/pdf-converter/formID/fill-pdf?submissionID=submissionID&apikey=apiKey

    Replace what's in orange with their respective values.

    Please give it a try and let us know how it goes.

  • aimee2
    Replied on January 8, 2022 at 5:26 AM

    if i rember correctly u need to be loged in to the website to use that url, but ill try

  • aimee2
    Replied on January 8, 2022 at 5:46 AM
    concerning {"day":"24","month":"02","year":"2023"}}]'


    I use zapier, and the trigger is new form submission, the data passed to zapier for my date field is "08-01-2022"


    so if i want to create an api request via webhooks in zapier thats the value i have for field 22

    I cant use field 22 multiple times in the post request, zapier wont let me in their gui and i guess the jotform api also wont be happy.

    Do you know how i can format it?

    Seems strange that a date value in a field is constructed in bits and pieces.
    I can imagine this being ok when u create a form, and then the jotform platform parses this into a single value and stores it (as it does, the day month and year are not stored sepereatly)
    But it makes no sense to post a date this way does it?

    Are u sure thats how it should be done?

  • aimee2
    Replied on January 8, 2022 at 5:56 AM

    Hi Amin,


    about Please use the below API endpoint instead to bypass the CORS error.

    https://eu-api.jotform.com/pdf-converter/formID/fill-pdf?submissionID=submissionID&apikey=apiKey

    Replace what's in orange with their respective values.

    Please give it a try and let us know how it goes.



    I tried, it seems fine now thanks. I just need to figure out with zapier how i can acess or view that file now ))

    Is there a way to just get the email after submission via API? Its easier as i can catch and parse the email

  • Amin JotForm Support
    Replied on January 8, 2022 at 6:13 AM

    Hi again,

    "I cant use field 22 multiple times in the post request, zapier wont let me in their gui and i guess the jotform api also wont be happy."

    Why do you think it's not possible to use a field multiple times in a post request to our API?

    Anyhow, a workaround would be using the dateString function as shown below.

    1641618204 61d91b1c40700  Screenshot 10

    1641617570 61d918a24c2ee  Screenshot 21

    Then use the Substring widget to divide the date string into day, month and year as shown below.

    https://www.jotform.com/220069452768058

    1641618131 61d91ad333906  Screenshot 32

    "Is there a way to just get the email after submission via API?"

    No, our API can't trigger emails, unfortunately.

    Should you have any further inquiries, we will be more than happy to help.

  • aimee2
    Replied on January 8, 2022 at 6:48 AM

    Hi Amin,

    and thanks again!
    The gui of zaier webhooks does not allow the same key (duplicate key error)

    If i need to construct the api request myself (zaier calls it a RAW request), then i get lost in formatting.

    I am a ships captain, not a programmer.


    The problem is that the jotform integration in zapier gets the form submission from jotform, and that date field value is passed as 7-1-2022, not as different fields.

    So even if i could use number 22 multiple times, i still would not have the data pieces to put into the request as it comes from jotform to zapier as a date, not seperate day month year

    1641642453 61d979d59ef90 Schermopname (3 Screenshot 10

  • aimee2
    Replied on January 8, 2022 at 6:49 AM

    but lets forget about the date for now, ill make it into a text field and be done with it, i dont need to calculate with the data anyway

  • John Support Team Lead
    Replied on January 8, 2022 at 7:53 AM

    I'm not familiar with Webhooks by Zapier but have you tried using FORMATTER in your workflow?

    This app allows you to use the SPLIT TEXT option enabling you to split the dates into separate fields.

    1641646348 61d9890cba152  Screenshot 10

    Then this will be the result:

    1641646382 61d9892e24ccc  Screenshot 21

    Please try using the said app and see if that worked for you.

  • aimee2
    Replied on January 8, 2022 at 8:03 AM

    thats a great idea!!!


    ill try and let u know, many thanks!


    For the moment i just created a text field, then used conditional logic to copy the value from date field to text field, it also works


    Thansk a lot for your support

  • aimee2
    Replied on January 8, 2022 at 12:52 PM

    That worked like a charm jOhn Rex! many thanks

  • John Support Team Lead
    Replied on January 8, 2022 at 1:58 PM

    It's good to know that it worked!

    Let us know here if you need further assistance.