├── composer.json ├── README.md ├── LICENSE └── JotForm.php /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jotform/jotform-api-php", 3 | "version" : "1.0.0-dev", 4 | "license": "GPL-3.0+", 5 | "homepage": "http://api.jotform.com", 6 | "support": { 7 | "email": "api@jotform.com", 8 | "wiki": "http://api.jotform.com" 9 | }, 10 | "require": { 11 | "php": ">=5.3.0" 12 | }, 13 | "autoload": { 14 | "classmap": [ 15 | "JotForm.php" 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jotform-api-php 2 | =============== 3 | [JotForm API](https://api.jotform.com/docs/) - PHP Client 4 | 5 | 6 | ### Installation 7 | 8 | Install via git clone: 9 | 10 | $ git clone git://github.com/jotform/jotform-api-php.git 11 | $ cd jotform-api-php 12 | 13 | or 14 | 15 | Install via Composer package manager (https://getcomposer.org/) 16 | 17 | _composer.json_ 18 | ```json 19 | { 20 | "require": { 21 | "jotform/jotform-api-php": "dev-master" 22 | } 23 | } 24 | ``` 25 | 26 | $ php composer.phar install 27 | 28 | ### Documentation 29 | 30 | You can find the docs for the API of this client at [https://api.jotform.com/docs/](https://api.jotform.com/docs) 31 | 32 | ### Authentication 33 | 34 | JotForm API requires API key for all user related calls. You can create your API Keys at [API section](https://www.jotform.com/myaccount/api) of My Account page. 35 | 36 | ### Examples 37 | 38 | Print all forms of the user 39 | 40 | ```php 41 | getForms(); 47 | 48 | foreach ($forms as $form) { 49 | print $form["title"]; 50 | } 51 | 52 | ?> 53 | ``` 54 | Get submissions of the latest form 55 | 56 | ```php 57 | getForms(0, 1, null, null); 65 | 66 | $latestForm = $forms[0]; 67 | 68 | $latestFormID = $latestForm["id"]; 69 | 70 | $submissions = $jotformAPI->getFormSubmissions($latestFormID); 71 | 72 | var_dump($submissions); 73 | 74 | } 75 | catch (Exception $e) { 76 | var_dump($e->getMessage()); 77 | } 78 | 79 | ?> 80 | ``` 81 | 82 | Get latest 100 submissions ordered by creation date 83 | 84 | ```php 85 | getSubmissions(0, 100, null, "created_at"); 93 | 94 | var_dump($submissions); 95 | } 96 | catch (Exception $e) { 97 | var_dump($e->getMessage()); 98 | } 99 | 100 | ?> 101 | ``` 102 | 103 | Submission and form filter examples 104 | 105 | ```php 106 | "239252191641336722", 115 | "created_at:gt" => "2013-07-09 07:48:34", 116 | ); 117 | 118 | $subs = $jotformAPI->getSubmissions(0, 0, $filter, ""); 119 | var_dump($subs); 120 | 121 | $filter = array( 122 | "id:gt" => "239176717911737253", 123 | ); 124 | 125 | $formSubs = $jotformAPI->getForms(0, 0, 2, $filter); 126 | var_dump($formSubs); 127 | } catch (Exception $e) { 128 | var_dump($e->getMessage()); 129 | } 130 | 131 | ?> 132 | ``` 133 | 134 | Delete last 50 submissions 135 | 136 | ```php 137 | getSubmissions(0, 50, null, null); 145 | 146 | foreach ($submissions as $submission) { 147 | $result = $jotformAPI->deleteSubmission($submission["id"]); 148 | print $result; 149 | } 150 | } 151 | catch (Exception $e) { 152 | var_dump($e->getMessage()); 153 | } 154 | 155 | ?> 156 | ``` 157 | 158 | First the _JotForm_ class is included from the _jotform-api-php/JotForm.php_ file. This class provides access to JotForm's API. You have to create an API client instance with your API key. 159 | In case of an exception (wrong authentication etc.), you can catch it or let it fail with a fatal error. 160 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {{description}} 294 | Copyright (C) {{year}} {{fullname}} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /JotForm.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 22 | $this->debugMode = $debugMode; 23 | $this->outputType = strtolower($outputType); 24 | $user = $this->getUser(); 25 | # set base url for EU users 26 | if (isset($user['euOnly'])) { 27 | $this->baseURL = 'https://eu-api.jotform.com'; 28 | } 29 | } 30 | 31 | public function __get($property) { 32 | if (property_exists($this, $property)) { 33 | return $this->$property; 34 | } 35 | } 36 | 37 | public function __set($property, $value) { 38 | if (property_exists($this, $property)) { 39 | $this->$property = $value; 40 | } 41 | } 42 | 43 | private function debugLog($str) { 44 | if ($this->debugMode) { 45 | print_r(PHP_EOL); 46 | print_r($str); 47 | } 48 | } 49 | 50 | private function debugDump($obj) { 51 | if ($this->debugMode) { 52 | print_r(PHP_EOL); 53 | var_dump($obj); 54 | } 55 | } 56 | 57 | private function executeHttpRequest($path, $method, $params = []) { 58 | if ($this->outputType != 'json') { 59 | $path = "{$path}.xml"; 60 | } 61 | 62 | $url = implode('/', [$this->baseURL, $this->apiVersion, $path]); 63 | 64 | $this->debugDump($params); 65 | 66 | if ($method == 'GET' && $params != null) { 67 | $params_array = []; 68 | foreach ($params as $key => $value) { 69 | $params_array[] = "{$key}={$value}"; 70 | } 71 | $params_string = '?' . implode('&', $params_array); 72 | unset($params_array); 73 | $url = $url . $params_string; 74 | $this->debugLog('params string: ' . $params_string); 75 | } 76 | 77 | $this->debugLog('fetching url: ' . $url); 78 | 79 | $ch = curl_init(); 80 | 81 | curl_setopt($ch, CURLOPT_URL, $url); 82 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 83 | curl_setopt($ch, CURLOPT_USERAGENT, 'JOTFORM_PHP_WRAPPER'); 84 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['APIKEY: ' . $this->apiKey]); 85 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 86 | 87 | switch ($method) { 88 | case 'POST': 89 | $this->debugLog('posting'); 90 | curl_setopt($ch, CURLOPT_POST, true); 91 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 92 | break; 93 | case 'PUT': 94 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 95 | curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 96 | break; 97 | case 'DELETE': 98 | $this->debugLog('delete'); 99 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); 100 | break; 101 | } 102 | 103 | $result = curl_exec($ch); 104 | 105 | if ($result == false) { 106 | throw new Exception(curl_error($ch), 400); 107 | } 108 | 109 | $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); 110 | $this->debugLog('http code is: ' . $http_status); 111 | 112 | if ($this->outputType == 'json') { 113 | $result_obj = json_decode($result, true); 114 | } else { 115 | $result_obj = utf8_decode($result); 116 | } 117 | 118 | if ($http_status != 200) { 119 | switch ($http_status) { 120 | case 400: 121 | case 403: 122 | case 404: 123 | throw new JotFormException($result_obj["message"], $http_status); 124 | break; 125 | case 401: 126 | throw new JotFormException("Invalid API key or Unauthorized API call", $http_status); 127 | break; 128 | case 503: 129 | throw new JotFormException("Service is unavailable, rate limits etc exceeded!", $http_status); 130 | break; 131 | 132 | default: 133 | throw new JotFormException($result_obj["info"], $http_status); 134 | break; 135 | } 136 | } 137 | 138 | curl_close($ch); 139 | 140 | if ($this->outputType == 'json') { 141 | if (isset($result_obj['content'])) { 142 | return $result_obj['content']; 143 | } else { 144 | return $result_obj; 145 | } 146 | } else { 147 | return $result_obj; 148 | } 149 | } 150 | 151 | private function executeGetRequest($url, $params = []) { 152 | return $this->executeHttpRequest($url, 'GET', $params); 153 | } 154 | 155 | private function executePostRequest($url, $params) { 156 | return $this->executeHttpRequest($url, 'POST', $params); 157 | } 158 | 159 | private function executePutRequest($url, $params) { 160 | return $this->executeHttpRequest($url, 'PUT', $params); 161 | } 162 | 163 | private function executeDeleteRequest($url, $params = []) { 164 | return $this->executeHttpRequest($url, 'DELETE', $params); 165 | } 166 | 167 | private function createConditions($offset, $limit, $filter, $orderby) { 168 | $params = []; 169 | foreach (['offset', 'limit', 'filter', 'orderby'] as $arg) { 170 | if (${$arg}) { 171 | $params[strtolower($arg)] = ${$arg}; 172 | if ($arg == "filter") { 173 | $params[$arg] = urlencode(json_encode($params[$arg])); 174 | } 175 | } 176 | } 177 | return $params; 178 | } 179 | 180 | private function createHistoryQuery($action, $date, $sortBy, $startDate, $endDate) { 181 | foreach (['action', 'date', 'sortBy', 'startDate', 'endDate'] as $arg) { 182 | if (${$arg}) { 183 | $params[$arg] = ${$arg}; 184 | } 185 | } 186 | return $params; 187 | } 188 | 189 | /** 190 | * [getUser Get user account details for a JotForm user] 191 | * @return [array] [Returns user account type, avatar URL, name, email, website URL and account limits.] 192 | */ 193 | public function getUser() { 194 | $res = $this->executeGetRequest('user'); 195 | return $res; 196 | } 197 | 198 | /** 199 | * [getUserUsage Get number of form submissions received this month] 200 | * @return [array] [Returns number of submissions, number of SSL form submissions, payment form submissions and upload space used by user.] 201 | */ 202 | public function getUsage(){ 203 | return $this->executeGetRequest('user/usage'); 204 | } 205 | 206 | /** 207 | * [getForms Get a list of forms for this account] 208 | * @param [integer] $offset [Start of each result set for form list. (optional)] 209 | * @param [integer] $limit [Number of results in each result set for form list. (optional)] 210 | * @param [array] $filter [Filters the query results to fetch a specific form range.(optional)] 211 | * @param [string] $orderBy [Order results by a form field name. (optional)] 212 | * @return [array] [Returns basic details such as title of the form, when it was created, number of new and total submissions.] 213 | */ 214 | public function getForms($offset = 0, $limit = 0, $filter = null, $orderby = null) { 215 | $params = $this->createConditions($offset, $limit, $filter, $orderby); 216 | return $this->executeGetRequest('user/forms', $params); 217 | } 218 | 219 | /** 220 | * [getSubmissions Get a list of submissions for this account] 221 | * @param [int] $offset [Start of each result set for form list. (optional)] 222 | * @param [int] $limit [Number of results in each result set for form list. (optional)] 223 | * @param [array] $filter [Filters the query results to fetch a specific form range.(optional)] 224 | * @param [string] $orderBy [Order results by a form field name. (optional)] 225 | * @return [array] [Returns basic details such as title of the form, when it was created, number of new and total submissions.] 226 | */ 227 | public function getSubmissions($offset = 0, $limit = 0, $filter = null, $orderby = null) { 228 | $params = $this->createConditions($offset, $limit, $filter, $orderby); 229 | return $this->executeGetRequest('user/submissions', $params); 230 | } 231 | 232 | /** 233 | * [getUserSubusers Get a list of sub users for this account] 234 | * @return [array] [Returns list of forms and form folders with access privileges.] 235 | */ 236 | public function getSubusers() { 237 | return $this->executeGetRequest('user/subusers'); 238 | } 239 | 240 | /** 241 | * [getUserFolders Get a list of form folders for this account] 242 | * @return [array] [Returns name of the folder and owner of the folder for shared folders.] 243 | */ 244 | public function getFolders() { 245 | return $this->executeGetRequest('user/folders'); 246 | } 247 | 248 | /** 249 | * [getReports List of URLS for reports in this account] 250 | * @return [array] [Returns reports for all of the forms. ie. Excel, CSV, printable charts, embeddable HTML tables.] 251 | */ 252 | public function getReports() { 253 | return $this->executeGetRequest('user/reports'); 254 | } 255 | 256 | /** 257 | * [getSettings Get user's settings for this account] 258 | * @return [array] [Returns user's time zone and language.] 259 | */ 260 | public function getSettings() { 261 | return $this->executeGetRequest('user/settings'); 262 | } 263 | 264 | /** 265 | * [updateSettings Update user's settings] 266 | * @param [array] $settings [New user setting values with setting keys] 267 | * @return [array] [Returns changes on user settings] 268 | */ 269 | public function updateSettings($settings) { 270 | return $this->executePostRequest('user/settings', $settings); 271 | } 272 | 273 | /** 274 | * [getHistory Get user activity log] 275 | * @param [enum] $action [Filter results by activity performed. Default is 'all'.] 276 | * @param [enum] $date [Limit results by a date range. If you'd like to limit results by specific dates you can use startDate and endDate fields instead.] 277 | * @param [enum] $sortBy [Lists results by ascending and descending order.] 278 | * @param [string] $startDate [Limit results to only after a specific date. Format: MM/DD/YYYY.] 279 | * @param [string] $endDate [Limit results to only before a specific date. Format: MM/DD/YYYY.] 280 | * @return [array] [Returns activity log about things like forms created/modified/deleted, account logins and other operations.] 281 | */ 282 | public function getHistory($action = null, $date = null, $sortBy = null, $startDate = null, $endDate = null) { 283 | $params = $this->createHistoryQuery($action, $date, $sortBy, $startDate, $endDate); 284 | return $this->executeGetRequest('user/history', $params); 285 | } 286 | 287 | /** 288 | * [getForm Get basic information about a form.] 289 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 290 | * @return [array] [Returns form ID, status, update and creation dates, submission count etc.] 291 | */ 292 | public function getForm($formID) { 293 | return $this->executeGetRequest('form/' . $formID); 294 | } 295 | 296 | /** 297 | * [getFormQuestions Get a list of all questions on a form.] 298 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 299 | * @return [array] [Returns question properties of a form.] 300 | */ 301 | public function getFormQuestions($formID) { 302 | return $this->executeGetRequest("form/{$formID}/questions"); 303 | } 304 | 305 | /** 306 | *[getFormQuestion Get details about a question] 307 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 308 | * @param [integer] $qid [Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.] 309 | * @return [array] [Returns question properties like required and validation.] 310 | */ 311 | public function getFormQuestion($formID, $qid) { 312 | return $this->executeGetRequest("form/{$formID}/question/{$qid}"); 313 | } 314 | 315 | /** 316 | * [getFormSubmissions List of a form submissions] 317 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 318 | * @param [int] $offset [Start of each result set for form list. (optional)] 319 | * @param [int] $limit [Number of results in each result set for form list. (optional)] 320 | * @param [array] $filter [Filters the query results to fetch a specific form range.(optional)] 321 | * @param [string] $orderBy [Order results by a form field name. (optional)] 322 | * @return [array] [Returns submissions of a specific form.] 323 | */ 324 | public function getFormSubmissions($formID, $offset = 0, $limit = 0, $filter = null, $orderby = null) { 325 | $params = $this->createConditions($offset, $limit, $filter, $orderby); 326 | return $this->executeGetRequest("form/{$formID}/submissions", $params); 327 | } 328 | 329 | /** 330 | * [createFormSubmissions Submit data to this form using the API] 331 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 332 | * @param [array] $submission [Submission data with question IDs.] 333 | * @return [array] [Returns posted submission ID and URL.] 334 | */ 335 | public function createFormSubmission($formID, $submission) { 336 | $sub = []; 337 | foreach ($submission as $key => $value) { 338 | if (strpos($key, '_')) { 339 | $qid = substr($key, 0, strpos($key, '_')); 340 | $type = substr($key, strpos($key, '_') + 1); 341 | $sub["submission[{$qid}][{$type}]"] = $value; 342 | } else { 343 | $sub["submission[{$key}]"] = $value; 344 | } 345 | } 346 | return $this->executePostRequest("form/{$formID}/submissions", $sub); 347 | } 348 | 349 | /** 350 | * [createFormSubmissions Submit data to this form using the API] 351 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 352 | * @param [json] $submissions [Submission data with question IDs.] 353 | * @return [array] 354 | */ 355 | public function createFormSubmissions($formID, $submissions) { 356 | return $this->executePutRequest("form/" . $formID . "/submissions", $submissions); 357 | } 358 | 359 | /** 360 | * [getFormFiles List of files uploaded on a form] 361 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 362 | * @return [array] [Returns uploaded file information and URLs on a specific form.] 363 | */ 364 | public function getFormFiles($formID) { 365 | return $this->executeGetRequest("form/{$formID}/files"); 366 | } 367 | 368 | /** 369 | * [getFormWebhooks Get list of webhooks for a form] 370 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 371 | * @return [array] [Returns list of webhooks for a specific form.] 372 | */ 373 | public function getFormWebhooks($formID) { 374 | return $this->executeGetRequest("form/{$formID}/webhooks"); 375 | } 376 | 377 | /** 378 | * [createFormWebhook Add a new webhook] 379 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 380 | * @param [string] $webhookURL [Webhook URL is where form data will be posted when form is submitted.] 381 | * @return [array] [Returns list of webhooks for a specific form.] 382 | */ 383 | public function createFormWebhook($formID, $webhookURL) { 384 | return $this->executePostRequest("form/{$formID}/webhooks", ['webhookURL' => $webhookURL]); 385 | } 386 | 387 | /** 388 | * [deleteFormWebhook] [Delete a specific webhook of a form.] 389 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 390 | * @param [integer] $webhookID [You can get webhook IDs when you call /form/{formID}/webhooks.] 391 | * @return [array] [Returns remaining webhook URLs of form.] 392 | */ 393 | public function deleteFormWebhook($formID, $webhookID) { 394 | return $this->executeDeleteRequest("form/{$formID}/webhooks/{$webhookID}", null); 395 | } 396 | 397 | /** 398 | * [getSubmission Get submission data] 399 | * @param [integer] $sid [You can get submission IDs when you call /form/{id}/submissions.] 400 | * @return [array] [Returns information and answers of a specific submission.] 401 | */ 402 | public function getSubmission($sid) { 403 | return $this->executeGetRequest("submission/{$sid}"); 404 | } 405 | 406 | /** 407 | * [getReport Get report details] 408 | * @param [integer] $reportID [You can get a list of reports from /user/reports.] 409 | * @return [array] [Returns properties of a speceific report like fields and status.] 410 | */ 411 | public function getReport($reportID) { 412 | return $this->executeGetRequest("report/{$reportID}"); 413 | } 414 | 415 | /** 416 | * [getFolder Get folder details] 417 | * @param [integer] $folderID [You can get a list of folders from /user/folders.] 418 | * @return [array] [Returns a list of forms in a folder, and other details about the form such as folder color.] 419 | */ 420 | public function getFolder($folderID) { 421 | return $this->executeGetRequest("folder/{$folderID}"); 422 | } 423 | 424 | /** 425 | * [createFolder Create a folder] 426 | * @param [array] $folderProperties [Properties of new folder.] 427 | * @return [array] [New folder.] 428 | */ 429 | public function createFolder($folderProperties) { 430 | return $this->executePostRequest('folder', $folderProperties); 431 | } 432 | 433 | /** 434 | * [deleteFolder Delete a specific folder and its subfolders] 435 | * @param [string] $folderID [You can get a list of folders from /user/folders.] 436 | * @return [array] [Returns status of request.] 437 | */ 438 | public function deleteFolder($folderID) { 439 | return $this->executeDeleteRequest("folder/{$folderID}", null); 440 | } 441 | 442 | /** 443 | * [updateFolder Update a specific folder] 444 | * @param [string] $folderID [You can get a list of folders from /user/folders.] 445 | * @param [json] $folderProperties [New properties of the specified folder.] 446 | * @return [array] [Returns status of request.] 447 | */ 448 | public function updateFolder($folderID, $folderProperties) { 449 | return $this->executePutRequest("folder/{$folderID}", $folderProperties); 450 | } 451 | 452 | /** 453 | * [addFormsToFolder Add forms to the specified folder] 454 | * @param [string] $folderID [You can get the list of folders from /user/folders.] 455 | * @param [array] $formIDs [You can get the list of forms from /user/forms.] 456 | * @return [array] [Returns status of request.] 457 | */ 458 | public function addFormsToFolder($folderID, $formIDs) { 459 | $formattedFormIDs = json_encode(["forms" => $formIDs]); 460 | return $this->updateFolder($folderID, $formattedFormIDs); 461 | } 462 | 463 | /** 464 | * [addFormToFolder Add a form to the specified folder] 465 | * @param [string] $folderID [You can get the list of folders from /user/folders.] 466 | * @param [string] $formID [You can get the list of forms from /user/forms.] 467 | * @return [array] [Returns status of request.] 468 | */ 469 | public function addFormToFolder($folderID, $formID) { 470 | $formattedFormID = json_encode(["forms" => [$formID]]); 471 | return $this->updateFolder($folderID, $formattedFormID); 472 | } 473 | 474 | /** 475 | * [getFormProperties Get a list of all properties on a form] 476 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 477 | * @return [array] [Returns form properties like width, expiration date, style etc.] 478 | */ 479 | public function getFormProperties($formID) { 480 | return $this->executeGetRequest("form/{$formID}/properties"); 481 | } 482 | 483 | /** 484 | * [getFormProperty Get a specific property of the form] 485 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 486 | * @param [string] $propertyKey [You can get property keys when you call /form/{id}/properties.] 487 | * @return [array] [Returns given property key value.] 488 | */ 489 | public function getFormProperty($formID, $propertyKey) { 490 | return $this->executeGetRequest("form/{$formID}/properties/{$propertyKey}"); 491 | } 492 | 493 | /** 494 | * [getFormReports Get all the reports of a form, such as excel, csv, grid, html, etc.] 495 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 496 | * @return [array] [Returns a list of reports in a form, and other details about the reports such as title.] 497 | */ 498 | public function getFormReports($formID) { 499 | return $this->executeGetRequest("form/{$formID}/reports"); 500 | } 501 | 502 | /** 503 | * [createReport Create new report of a form] 504 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 505 | * @param [array] $report [Report details. List type, title etc.] 506 | * @return [array] [Returns report details and URL.] 507 | */ 508 | public function createReport($formID, $report) { 509 | return $this->executePostRequest("form/{$formID}/reports", $report); 510 | } 511 | 512 | /** 513 | * [deleteSubmission Delete a single submission] 514 | * @param [integer] $sid [You can get submission IDs when you call /user/submissions.] 515 | * @return [array] [Returns status of request.] 516 | */ 517 | public function deleteSubmission($sid) { 518 | return $this->executeDeleteRequest("submission/{$sid}"); 519 | } 520 | 521 | /** 522 | * [editSubmission Edit a single submission] 523 | * @param [integer] $sid [You can get submission IDs when you call /form/{id}/submissions.] 524 | * @param [array] $submission [New submission data with question IDs.] 525 | * @return [array] [Returns status of request.] 526 | */ 527 | public function editSubmission($sid, $submission) { 528 | $sub = []; 529 | foreach ($submission as $key => $value) { 530 | if (strpos($key, '_') && $key != 'created_at') { 531 | $qid = substr($key, 0, strpos($key, '_')); 532 | $type = substr($key, strpos($key, '_') + 1); 533 | $sub["submission[{$qid}][{$type}]"] = $value; 534 | } else { 535 | $sub["submission[{$key}]"] = $value; 536 | } 537 | } 538 | return $this->executePostRequest("submission/" . $sid, $sub); 539 | } 540 | 541 | /** 542 | * [cloneForm Clone a single form] 543 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 544 | * @return [array] [Returns status of request.] 545 | */ 546 | public function cloneForm($formID) { 547 | return $this->executePostRequest("form/{$formID}/clone", null); 548 | } 549 | 550 | /** 551 | * [deleteFormQuestion Delete a single form question] 552 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 553 | * @param [integer] $qid [Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.] 554 | * @return [array] [Returns status of request.] 555 | */ 556 | public function deleteFormQuestion($formID, $qid) { 557 | return $this->executeDeleteRequest("form/{$formID}/question/{$qid}", null); 558 | } 559 | 560 | /** 561 | * [createFormQuestion Add new question to specified form] 562 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 563 | * @param [array] $question [New question properties like type and text.] 564 | * @return [array] [Returns properties of new question.] 565 | */ 566 | public function createFormQuestion($formID, $question) { 567 | $params = []; 568 | foreach ($question as $key => $value) { 569 | $params["question[{$key}]"] = $value; 570 | } 571 | return $this->executePostRequest("form/{$formID}/questions", $params); 572 | } 573 | 574 | /** 575 | * [createFormQuestions Add new questions to specified form] 576 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 577 | * @param [json] $questions [New question properties like type and text.] 578 | * @return [array] [Returns properties of new questions.] 579 | */ 580 | public function createFormQuestions($formID, $questions) { 581 | return $this->executePutRequest("form/{$formID}/questions", $questions); 582 | } 583 | 584 | /** 585 | * [editFormQuestion Add or edit a single question properties] 586 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 587 | * @param [integer] $qid [Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.] 588 | * @param [array] $questionProperties [New question properties like text and order.] 589 | * @return [array] [Returns edited property and type of question.] 590 | */ 591 | public function editFormQuestion($formID, $qid, $questionProperties) { 592 | $question = []; 593 | foreach ($questionProperties as $key => $value) { 594 | $question["question[{$key}]"] = $value; 595 | } 596 | return $this->executePostRequest("form/{$formID}/question/{$qid}", $question); 597 | } 598 | 599 | /** 600 | * [setFormProperties Add or edit properties of a specific form] 601 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 602 | * @param [array] $formProperties [New properties like label width.] 603 | * @return [array] [Returns edited properties.] 604 | */ 605 | public function setFormProperties($formID, $formProperties) { 606 | $properties = []; 607 | foreach ($formProperties as $key => $value) { 608 | $properties["properties[{$key}]"] = $value; 609 | } 610 | return $this->executePostRequest("form/{$formID}/properties", $properties); 611 | } 612 | 613 | /** 614 | *[setMultipleFormProperties Add or edit properties of a specific form] 615 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 616 | * @param [json] $formProperties [New properties like label width.] 617 | * @return [array] [Returns edited properties.] 618 | */ 619 | public function setMultipleFormProperties($formID, $formProperties) { 620 | return $this->executePutRequest("form/{$formID}/properties", $formProperties); 621 | } 622 | 623 | /** 624 | * [createForm Create a new form] 625 | * @param [array] $form [Questions, properties and emails of new form.] 626 | * @return [array] [Returns new form.] 627 | */ 628 | public function createForm($form) { 629 | $params = []; 630 | foreach ($form as $key => $value) { 631 | foreach ($value as $k => $v) { 632 | if ($key == "properties") { 633 | $params["{$key}[{$k}]"] = $v; 634 | } else { 635 | foreach ($v as $a => $b) { 636 | $params["{$key}[{$k}][{$a}]"] = $b; 637 | } 638 | } 639 | } 640 | } 641 | return $this->executePostRequest('user/forms', $params); 642 | } 643 | 644 | /** 645 | * [createForm Create new forms] 646 | * @param [json] $form [Questions, properties and emails of forms.] 647 | * @return [array] [Returns new forms.] 648 | */ 649 | public function createForms($forms) { 650 | return $this->executePutRequest('user/forms', $forms); 651 | } 652 | 653 | /** 654 | * [deleteForm Delete a specific form] 655 | * @param [integer] $formID [Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.] 656 | * @return [array] [Returns roperties of deleted form.] 657 | */ 658 | public function deleteForm($formID) { 659 | return $this->executeDeleteRequest("form/{$formID}", null); 660 | } 661 | 662 | /** 663 | * [registerUser Register with username, password and email] 664 | * @param [array] $userDetails [username, password and email to register a new user] 665 | * @return [array] [Returns new user's details] 666 | */ 667 | public function registerUser($userDetails) { 668 | return $this->executePostRequest('user/register', $userDetails); 669 | } 670 | 671 | /** 672 | * [loginUser Login user with given credentials] 673 | * @param [array] $credentials [Username, password, application name and access type of user] 674 | * @return [array] [Returns logged in user's settings and app key.] 675 | */ 676 | public function loginUser($credentials) { 677 | return $this->executePostRequest('user/login', $credentials); 678 | } 679 | 680 | /** 681 | * [logoutUser Logout User] 682 | * @return [array] [Status of request] 683 | */ 684 | public function logoutUser() { 685 | return $this->executeGetRequest('user/logout'); 686 | } 687 | 688 | /** 689 | * [getPlan Get details of a plan] 690 | * @param [string] $planName [Name of the requested plan. FREE, PREMIUM etc.] 691 | * @return [array] [Returns details of a plan] 692 | */ 693 | public function getPlan($planName) { 694 | return $this->executeGetRequest("system/plan/{$planName}"); 695 | } 696 | 697 | /** 698 | * [deleteReport Delete a specific report] 699 | * @param [integer] $reportID [You can get a list of reports from /user/reports.] 700 | * @return [array] [Returns status of request.] 701 | */ 702 | public function deleteReport($reportID) { 703 | return $this->executeDeleteRequest("report/{$reportID}", null); 704 | } 705 | } 706 | 707 | class JotFormException extends Exception { 708 | 709 | } 710 | --------------------------------------------------------------------------------