Downloading form PDF from jotform via php script

  • krakerjak
    Asked on October 14, 2016 at 11:21 AM

    Hello,

    I am using PHP to download the pdf form each time a form is submitted using a webhook to notify of a new submission and then PHP code to grab the new PDF of the specific submission using the url provided in your Jotform FAQ:

     

    $pdfurl = "https://submit.jotformpro.com/server.php?action=getSubmissionPDF&sid=$submissionID&formID=$formID";

    This has been working great for the past 7 months. The problem I have seen over the last month with this method is that about 50% of new submissions fail to successfully download the PDF from Jotform. The php error log is catching each of these failed download attempts as below:

     

    PHP Warning: file_get_contents(): Peer certificate CN=`*.jotform.com' did not match expected CN=`submit.jotformpro.com' in /home/****/functions.php on line 159 PHP Warning: file_get_contents(): Failed to enable crypto in /home/****/functions.php on line 159 PHP Warning: file_get_contents(https://submit.jotformpro.com/server.php?action=getSubmissionPDF&sid=***&formID=***): failed to open stream: operation failed in /home/****/functions.php on line 159

    Is there a new URL to use for downloading PDF forms? I have been getting these PHP warnings since mid August and about 50% of the time the PDF fails to download. Only 100 of 200 approx new submissions since mid august have failed. This section of the warning leads me to believe something changed and there is maybe a new URL to use for downloading PDF submissions:

    Peer certificate CN=`*.jotform.com' did not match expected CN=`submit.jotformpro.com'

  • David JotForm Support
    Replied on October 14, 2016 at 12:23 PM

    The only potential issue I can see is that your account is a Free account but is using the paid account submit URL to download the PDF.  Check the submit URL from this link:

    https://www.jotform.ca/form/53625611618253

    This should be the proper submit URL for your form.  It looks like the error is showing jotformpro.com is expected but jotform.com is the actual submit URL being used.  If you were previously on a paid account, the submit URL is jotformpro.com and it is jotform.com for Free accounts.  Updating your script to use the Free account submit URL should allow for more consistent delivery. 

  • krakerjak
    Replied on October 14, 2016 at 1:48 PM

    Thanks for your fast input.

    I can see the submit button posts to submit.jotform.ca so i will try using that vs submit.jotformpro.com

    A quick test with my formID and a random submission id results in a downloaded PDF. So far so good, ill let that go for a week and see if get any of the php warnings again. 

  • krakerjak
    Replied on October 17, 2016 at 1:40 PM

    submit.jotform.ca was also not working.

    Went with submit.jotform.com and the PHP warnings stopped and the PDF downloaded to my server (which hasn't been happening for the last 2 weeks).

  • Nik_C
    Replied on October 17, 2016 at 2:26 PM

    Thank you for letting us know.

    Let us know how it works and if the warnings stopped showing.

    Thank you!

  • krakerjak
    Replied on October 21, 2016 at 6:12 PM

    In the last week I have had 21 new submissions and all have downloaded ok!!!

    I would call this fixed.

     

    This poses a new question: If I were to get a subscription would I break my automated PDF grabbing system again because the replying CN would go back to submit.jotformpro.com and PHP's file_get_contents() would fail due to the CN not matching?

    If the API has a way of telling if you have a free or paid sub I could work around it.

     

    **Did some digging in the API and realized -- GET user/settings -- will tell me what type of account i currently hold and could adjust accordingly.

  • Elton Support Team Lead
    Replied on October 22, 2016 at 1:31 AM

    @krakerjak

    Great! Glad it worked for you now.

    As far as I know, downloading the PDF file does not actually require specific URL. For as long as it's non-EU URL, it should work fine. You can also use the default domain www.jotform.com, it should work.  However, like what my colleague has said, we always recommend using the domain name assigned to you to as it may perform better on your location.

    Regarding on getting the plan type, use this endpoint http://api.jotform.com/docs/#system-plan-planName

    If you also want to get the website URL assigned to you, use this http://api.jotform.com/docs/#user

    There's also a short URL to get the PDF file, this one looks neat :)

    https://www.jotform.com/pdf-submission/$submissionID

    If you need further assistance, let us know.

  • Elton Support Team Lead
    Replied on October 22, 2016 at 1:34 AM

    Sorry, I mean to say this URL for the plant type http://api.jotform.com/docs/#user-settings.

    I can see that you've just mentioned it in your post. :)