├── setup.py
├── README.md
├── LICENSE
├── jotform.html
└── jotform.py
/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup
2 |
3 | setup(
4 | name="jotform",
5 | url='http://api.jotform.com/docs/',
6 | version='1.2',
7 | description='JotForm API - Python Client',
8 | author='JotForm',
9 | author_email='api@jotform.com',
10 | py_modules=['jotform']
11 | )
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | jotform-api-python
2 | ===============
3 | [JotForm API](https://api.jotform.com/docs/) - Python Client
4 |
5 |
6 | ### Installation
7 |
8 | Install via git clone:
9 |
10 | $ git clone https://github.com/jotform/jotform-api-python.git
11 | $ cd jotform-api-python
12 |
13 | Install via pip (latest version)
14 |
15 | $ pip install git+https://github.com/jotform/jotform-api-python.git
16 |
17 | ### Documentation
18 |
19 | You can find the docs for the API of this client at [https://api.jotform.com/docs/](https://api.jotform.com/docs)
20 |
21 | ### Authentication
22 |
23 | 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.
24 |
25 | ### Examples
26 |
27 | Print all forms of the user
28 |
29 | ```python
30 | from jotform import *
31 |
32 | def main():
33 |
34 | jotformAPIClient = JotformAPIClient('YOUR API KEY')
35 |
36 | forms = jotformAPIClient.get_forms()
37 |
38 | for form in forms:
39 | print(form["title"])
40 |
41 | if __name__ == "__main__":
42 | main()
43 | ```
44 |
45 | Get submissions of the latest form
46 |
47 | ```python
48 | from jotform import *
49 |
50 | def main():
51 |
52 | jotformAPIClient = JotformAPIClient('YOUR API KEY')
53 |
54 | forms = jotformAPIClient.get_forms(None, 1, None, None)
55 |
56 | latestForm = forms[0]
57 |
58 | latestFormID = latestForm["id"]
59 |
60 | submissions = jotformAPIClient.get_form_submissions(latestFormID)
61 |
62 | print(submissions)
63 |
64 | if __name__ == "__main__":
65 | main()
66 | ```
67 |
68 | Get latest 100 submissions ordered by creation date
69 |
70 | ```python
71 | from jotform import *
72 |
73 | def main():
74 |
75 | jotformAPIClient = JotformAPIClient('YOUR API KEY')
76 |
77 | submissions = jotformAPIClient.get_submissions(0, 100, None, "created_at")
78 |
79 | print(submissions)
80 |
81 | if __name__ == "__main__":
82 | main()
83 | ```
84 |
85 | Submission and form filter examples
86 |
87 | ```python
88 | from jotform import *
89 |
90 | def main():
91 |
92 | jotformAPIClient = JotformAPIClient('YOUR API KEY')
93 |
94 | submission_filter = {"id:gt":"FORM ID", "created_at": "DATE"}
95 |
96 | submission = jotformAPIClient.get_submissions(0, 0, submission_filter, "")
97 | print(submission)
98 |
99 | form_filter = {"id:gt": "FORM ID"}
100 |
101 | forms = jotformAPIClient.get_forms(0,0, form_filter, "")
102 | print(forms)
103 |
104 | if __name__ == "__main__":
105 | main()
106 | ```
107 |
108 | Delete last 50 submissions
109 |
110 | ```python
111 | from jotform import *
112 |
113 | def main():
114 |
115 | jotformAPIClient = JotformAPIClient('YOUR API KEY')
116 |
117 | submissions = jotformAPIClient.get_submissions(0, 50, None, None)
118 |
119 | for submission in submissions:
120 | result = jotformAPIClient.delete_submission(submission["id"])
121 | print(result)
122 |
123 | if __name__ == "__main__":
124 | main()
125 | ```
126 |
127 | First the _JotformAPIClient_ class is included from the _jotform-api-python/jotform.py_ file. This class provides access to JotForm's API. You have to create an API client instance with your API key.
128 | In case of an exception (wrong authentication etc.), you can catch it or let it fail with a fatal error.
129 |
--------------------------------------------------------------------------------
/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.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Python: module jotform
4 |
5 |
6 |
12 | # -*- coding: utf-8 -*-
13 | #
14 | # Jotform API Wrapper
15 | # copyright : Interlogy LLC
16 | #
17 |
18 |
19 |
20 |
21 | Modules |
22 |
23 | | | |
24 | |
28 |
29 |
30 |
31 | Classes |
32 |
33 | | | |
34 |
35 | - JotformAPIClient
36 |
37 |
38 |
39 |
40 |
41 | class JotformAPIClient |
42 |
43 | | | |
44 | Methods defined here:
45 | - __init__(self, apiKey, debug=False, outputType='json')
46 |
47 | - clone_form(self, formID)
- Clone a single form.
48 |
49 | Args:
50 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
51 |
52 | Returns:
53 | Status of request.
54 |
55 | - create_conditions(self, offset, limit, filterArray, order_by)
56 |
57 | - create_form_submissions(self, formID, submission)
- Submit data to this form using the API.
58 |
59 | Args:
60 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
61 | submission (array): Submission data with question IDs.
62 |
63 | Returns:
64 | Posted submission ID and URL.
65 |
66 | - create_form_webhook(self, formID, webhookURL)
- Add a new webhook
67 |
68 | Args:
69 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
70 | webhookURL (string): Webhook URL is where form data will be posted when form is submitted.
71 |
72 | Returns:
73 | List of webhooks for a specific form.
74 |
75 | - delete_form_question(self, formID, qid)
- Delete a single form question.
76 |
77 | Args:
78 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
79 | qid (string): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
80 |
81 | Returns:
82 | Status of request.
83 |
84 | - delete_submission(self, sid)
- Delete a single submission.
85 |
86 | Args:
87 | sid (string): You can get submission IDs when you call /form/{id}/submissions.
88 |
89 | Returns:
90 | Status of request.
91 |
92 | - edit_submission(self, sid, submission)
- Edit a single submission.
93 |
94 | Args:
95 | sid (string): You can get submission IDs when you call /form/{id}/submissions.
96 | submission (array): New submission data with question IDs.
97 |
98 | Returns:
99 | Status of request.
100 |
101 | - fetch_url(self, url, params=None, method=None)
102 |
103 | - get_folder(self, folderID)
- Get folder details
104 |
105 | Args:
106 | folderID (string): Get a list of folders from /user/folders
107 |
108 | Returns:
109 | A list of forms in a folder, and other details about the form such as folder color.
110 |
111 | - get_folders(self)
- Get a list of form folders for this account.
112 |
113 | Returns:
114 | Name of the folder and owner of the folder for shared folders.
115 |
116 | - get_form(self, formID)
- Get basic information about a form.
117 |
118 | Args:
119 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
120 |
121 | Returns:
122 | Form ID, status, update and creation dates, submission count etc.
123 |
124 | - get_form_files(self, formID)
- List of files uploaded on a form.
125 |
126 | Args:
127 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
128 |
129 | Returns:
130 | Uploaded file information and URLs on a specific form.
131 |
132 | - get_form_properties(self, formID)
- Get a list of all properties on a form.
133 |
134 | Args:
135 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
136 |
137 | Returns:
138 | Form properties like width, expiration date, style etc.
139 |
140 | - get_form_property(self, formID, propertyKey)
- Get a specific property of the form.
141 |
142 | Args:
143 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
144 | propertyKey (string): You can get property keys when you call /form/{id}/properties.
145 |
146 | Returns:
147 | Given property key value.
148 |
149 | - get_form_question(self, formID, qid)
- Get details about a question
150 |
151 | Args:
152 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
153 | qid (string): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
154 |
155 | Returns:
156 | Question properties like required and validation.
157 |
158 | - get_form_questions(self, formID)
- Get a list of all questions on a form.
159 |
160 | Args:
161 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
162 |
163 | Returns:
164 | Question properties of a form.
165 |
166 | - get_form_submissions(self, formID, offset=None, limit=None, filterArray=None, order_by=None)
- List of a form submissions.
167 |
168 | Args:
169 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
170 | offset (string): Start of each result set for form list. (optional)
171 | limit (string): Number of results in each result set for form list. (optional)
172 | filterArray (array): Filters the query results to fetch a specific form range.(optional)
173 | order_by (string): Order results by a form field name. (optional)
174 |
175 | Returns:
176 | Submissions of a specific form.
177 |
178 | - get_form_webhooks(self, formID)
- Get list of webhooks for a form
179 |
180 | Args:
181 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
182 |
183 | Returns:
184 | List of webhooks for a specific form.
185 |
186 | - get_forms(self, offset=None, limit=None, filterArray=None, order_by=None)
- Get a list of forms for this account
187 |
188 | Args:
189 | offset (string): Start of each result set for form list. (optional)
190 | limit (string): Number of results in each result set for form list. (optional)
191 | filterArray (array): Filters the query results to fetch a specific form range.(optional)
192 | order_by (string): Order results by a form field name. (optional)
193 |
194 | Returns:
195 | Basic details such as title of the form, when it was created, number of new and total submissions.
196 |
197 | - get_history(self)
- Get user activity log.
198 |
199 | Returns:
200 | Activity log about things like forms created/modified/deleted, account logins and other operations.
201 |
202 | - get_report(self, reportID)
- Get report details
203 |
204 | Args:
205 | reportID (string): You can get a list of reports from /user/reports.
206 |
207 | Returns:
208 | Properties of a speceific report like fields and status.
209 |
210 | - get_reports(self)
- List of URLS for reports in this account.
211 |
212 | Returns:
213 | Reports for all of the forms. ie. Excel, CSV, printable charts, embeddable HTML tables.
214 |
215 | - get_settings(self)
- Get user's settings for this account.
216 |
217 | Returns:
218 | User's time zone and language.
219 |
220 | - get_submission(self, sid)
- Get submission data
221 |
222 | Args:
223 | sid (string): You can get submission IDs when you call /form/{id}/submissions.
224 |
225 | Returns:
226 | Information and answers of a specific submission.
227 |
228 | - get_submissions(self, offset=None, limit=None, filterArray=None, order_by=None)
- Get a list of submissions for this account.
229 |
230 | Args:
231 | offset (string): Start of each result set for form list. (optional)
232 | limit (string): Number of results in each result set for form list. (optional)
233 | filterArray (array): Filters the query results to fetch a specific form range.(optional)
234 | order_by (string): Order results by a form field name. (optional)
235 |
236 | Returns:
237 | Basic details such as title of the form, when it was created, number of new and total submissions.
238 |
239 | - get_subusers(self)
- Get a list of sub users for this account.
240 |
241 | Returns:
242 | List of forms and form folders with access privileges.
243 |
244 | - get_usage(self)
- Get number of form submissions received this month.
245 |
246 | Returns:
247 | Number of submissions, number of SSL form submissions, payment form submissions and upload space used by user.
248 |
249 | - get_user(self)
- Get user account details for a JotForm user.
250 |
251 | Returns:
252 | User account type, avatar URL, name, email, website URL and account limits.
253 |
254 | | |
255 |
256 |
257 |
258 | Data |
259 |
260 | | | |
261 | __author__ = 'canerbalci@gmail.com (Caner Balci)' |
262 |
263 |
264 |
265 | Author |
266 |
267 | | | |
268 | canerbalci@gmail.com (Caner Balci) |
269 |
--------------------------------------------------------------------------------
/jotform.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # JotForm API - Python Client
5 | #
6 | # copyright : 2020 JotForm, Inc.
7 | # link : http://www.jotform.com
8 | # version : 1.0
9 | # package : JotFormAPI
10 |
11 | import urllib.request, urllib.parse, urllib.error
12 | import json
13 |
14 | class JotformAPIClient:
15 | DEFAULT_BASE_URL = 'https://api.jotform.com/'
16 | EU_BASE_URL = 'https://eu-api.jotform.com/'
17 |
18 | __apiVersion = 'v1'
19 |
20 | __apiKey = None
21 | __debugMode = False
22 | __outputType = "json"
23 |
24 | def __init__(self, apiKey='', baseUrl=DEFAULT_BASE_URL, outputType='json', debug=False):
25 | self.__apiKey = apiKey
26 | self.__baseUrl = baseUrl
27 | self.__outputType = outputType.lower()
28 | self.__debugMode = debug
29 |
30 | def _log(self, message):
31 | if self.__debugMode:
32 | print(message)
33 |
34 | def set_baseurl(self, baseurl):
35 | self.__baseUrl = baseurl
36 |
37 | def get_debugMode(self):
38 | return self.__debugMode
39 | def set_debugMode(self, value):
40 | self.__debugMode = value
41 |
42 | def get_outputType(self):
43 | return self.__outputType
44 | def set_outputType(self, value):
45 | self.__outputType = value
46 |
47 | def fetch_url(self, url, params=None, method=None):
48 | if(self.__outputType != 'json'):
49 | url = url + '.xml'
50 |
51 | url = self.__baseUrl + self.__apiVersion + url
52 |
53 | self._log('fetching url ' + url)
54 | if (params):
55 | self._log(params)
56 |
57 | headers = {
58 | 'apiKey': self.__apiKey,
59 | 'User-Agent': 'JOTFORM_PYTHON_WRAPPER'
60 | }
61 |
62 | if (method == 'GET'):
63 | if (params):
64 | url = url + '?' + urllib.parse.urlencode(params)
65 |
66 | req = urllib.request.Request(url, headers=headers, data=None)
67 | elif (method == 'POST'):
68 | if (params):
69 | data = urllib.parse.urlencode(params).encode('utf-8')
70 | else:
71 | data = None
72 | req = urllib.request.Request(url, headers=headers, data=data)
73 | elif (method == 'DELETE'):
74 | req = urllib.request.Request(url, headers=headers, data=None)
75 | req.get_method = lambda: 'DELETE'
76 | elif (method == 'PUT'):
77 | if (params):
78 | params = params.encode("utf-8")
79 | req = urllib.request.Request(url, headers=headers, data=params)
80 | req.get_method = lambda: 'PUT'
81 |
82 | response = urllib.request.urlopen(req)
83 |
84 | if (self.__outputType == 'json'):
85 | responseObject = json.loads(response.read().decode('utf-8'))
86 | return responseObject['content']
87 | else:
88 | data = response.read()
89 | response.close()
90 | return data
91 |
92 | def create_conditions(self, offset, limit, filterArray, order_by):
93 | args = {'offset': offset, 'limit': limit, 'filter': filterArray, 'orderby': order_by}
94 | params = {}
95 |
96 | for key in list(args.keys()):
97 | if(args[key]):
98 | if(key == 'filter'):
99 | params[key] = json.dumps(args[key])
100 | else:
101 | params[key] = args[key]
102 |
103 | return params
104 |
105 | def create_history_query(self, action, date, sortBy, startDate, endDate):
106 | args = {'action': action, 'date': date, 'sortBy': sortBy, 'startDate': startDate, 'endDate': endDate}
107 | params = {}
108 |
109 | for key in list(args.keys()):
110 | if (args[key]):
111 | params[key] = args[key]
112 |
113 | return params
114 |
115 | def get_user(self):
116 | """Get user account details for a JotForm user.
117 |
118 | Returns:
119 | User account type, avatar URL, name, email, website URL and account limits.
120 | """
121 |
122 | return self.fetch_url('/user', method='GET')
123 |
124 | def get_usage(self):
125 | """Get number of form submissions received this month.
126 |
127 | Returns:
128 | Number of submissions, number of SSL form submissions, payment form submissions and upload space used by user.
129 | """
130 |
131 | return self.fetch_url('/user/usage', method='GET')
132 |
133 | def get_forms(self, offset=None, limit=None, filterArray=None, order_by=None):
134 | """Get a list of forms for this account
135 |
136 | Args:
137 | offset (string): Start of each result set for form list. (optional)
138 | limit (string): Number of results in each result set for form list. (optional)
139 | filterArray (array): Filters the query results to fetch a specific form range.(optional)
140 | order_by (string): Order results by a form field name. (optional)
141 |
142 | Returns:
143 | Basic details such as title of the form, when it was created, number of new and total submissions.
144 | """
145 |
146 | params = self.create_conditions(offset, limit, filterArray, order_by)
147 |
148 | return self.fetch_url('/user/forms', params, 'GET')
149 |
150 | def get_submissions(self, offset=None, limit=None, filterArray=None, order_by=None):
151 | """Get a list of submissions for this account.
152 |
153 | Args:
154 | offset (string): Start of each result set for form list. (optional)
155 | limit (string): Number of results in each result set for form list. (optional)
156 | filterArray (array): Filters the query results to fetch a specific form range.(optional)
157 | order_by (string): Order results by a form field name. (optional)
158 |
159 | Returns:
160 | Basic details such as title of the form, when it was created, number of new and total submissions.
161 | """
162 |
163 | params = self.create_conditions(offset, limit, filterArray, order_by)
164 |
165 | return self.fetch_url('/user/submissions', params, 'GET')
166 |
167 | def get_subusers(self):
168 | """Get a list of sub users for this account.
169 |
170 | Returns:
171 | List of forms and form folders with access privileges.
172 | """
173 |
174 | return self.fetch_url('/user/subusers', method='GET')
175 |
176 | def get_folders(self):
177 | """Get a list of form folders for this account.
178 |
179 | Returns:
180 | Name of the folder and owner of the folder for shared folders.
181 | """
182 |
183 | return self.fetch_url('/user/folders', method='GET')
184 |
185 | def get_reports(self):
186 | """List of URLS for reports in this account.
187 |
188 | Returns:
189 | Reports for all of the forms. ie. Excel, CSV, printable charts, embeddable HTML tables.
190 | """
191 |
192 | return self.fetch_url('/user/reports', method='GET')
193 |
194 | def get_settings(self):
195 | """Get user's settings for this account.
196 |
197 | Returns:
198 | User's time zone and language.
199 | """
200 |
201 | return self.fetch_url('/user/settings', method='GET')
202 |
203 | def update_settings(self, settings):
204 | """Update user's settings.
205 |
206 | Args:
207 | settings (array): New user setting values with setting keys
208 |
209 | Returns:
210 | Changes on user settings.
211 | """
212 |
213 | return self.fetch_url('/user/settings', settings, 'POST')
214 |
215 | def get_history(self, action=None, date=None, sortBy=None, startDate=None, endDate=None):
216 | """Get user activity log.
217 |
218 | Args:
219 | action (enum): Filter results by activity performed. Default is 'all'.
220 | date (enum): Limit results by a date range. If you'd like to limit results by specific dates you can use startDate and endDate fields instead.
221 | sortBy (enum): Lists results by ascending and descending order.
222 | startDate (string): Limit results to only after a specific date. Format: MM/DD/YYYY.
223 | endDate (string): Limit results to only before a specific date. Format: MM/DD/YYYY.
224 |
225 | Returns:
226 | Activity log about things like forms created/modified/deleted, account logins and other operations.
227 | """
228 |
229 | params = self.create_history_query(action, date, sortBy, startDate, endDate)
230 |
231 | return self.fetch_url('/user/history', params, 'GET')
232 |
233 | def get_form(self, formID):
234 | """Get basic information about a form.
235 |
236 | Args:
237 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
238 |
239 | Returns:
240 | Form ID, status, update and creation dates, submission count etc.
241 | """
242 |
243 | return self.fetch_url('/form/' + formID, method='GET')
244 |
245 | def get_form_questions(self, formID):
246 | """Get a list of all questions on a form.
247 |
248 | Args:
249 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
250 |
251 | Returns:
252 | Question properties of a form.
253 | """
254 |
255 | return self.fetch_url('/form/' + formID + '/questions', method='GET')
256 |
257 | def get_form_question(self, formID, qid):
258 | """Get details about a question
259 |
260 | Args:
261 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
262 | qid (string): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
263 |
264 | Returns:
265 | Question properties like required and validation.
266 | """
267 | return self.fetch_url('/form/' + formID + '/question/' + qid, method='GET')
268 |
269 | def get_form_submissions(self, formID, offset=None, limit=None, filterArray=None, order_by=None):
270 | """List of a form submissions.
271 |
272 | Args:
273 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
274 | offset (string): Start of each result set for form list. (optional)
275 | limit (string): Number of results in each result set for form list. (optional)
276 | filterArray (array): Filters the query results to fetch a specific form range.(optional)
277 | order_by (string): Order results by a form field name. (optional)
278 |
279 | Returns:
280 | Submissions of a specific form.
281 | """
282 |
283 | params = self.create_conditions(offset, limit, filterArray, order_by)
284 |
285 | return self.fetch_url('/form/' + formID + '/submissions', params, 'GET')
286 |
287 | def create_form_submission(self, formID, submission):
288 | """Submit data to this form using the API.
289 |
290 | Args:
291 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
292 | submission (array): Submission data with question IDs.
293 |
294 | Returns:
295 | Posted submission ID and URL.
296 | """
297 |
298 | sub = {}
299 |
300 | for key in submission.keys():
301 | if "_" in key:
302 | sub['submission[' + key[0:key.find("_")] + '][' + key[key.find("_")+1:len(key)] + ']'] = submission[key]
303 | else:
304 | sub['submission[' + key + ']'] = submission[key]
305 |
306 | return self.fetch_url('/form/' + formID + '/submissions', sub, 'POST')
307 |
308 | def create_form_submissions(self, formID, submissions):
309 | """Submit data to this form using the API.
310 |
311 | Args:
312 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
313 | submission (json): Submission data with question IDs.
314 |
315 | Returns:
316 | Posted submission ID and URL.
317 | """
318 |
319 | return self.fetch_url('/form/' + formID + '/submissions', submissions, 'PUT')
320 |
321 | def get_form_files(self, formID):
322 | """List of files uploaded on a form.
323 |
324 | Args:
325 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
326 |
327 | Returns:
328 | Uploaded file information and URLs on a specific form.
329 | """
330 |
331 | return self.fetch_url('/form/' + formID + '/files', method='GET')
332 |
333 | def get_form_webhooks(self, formID):
334 | """Get list of webhooks for a form
335 |
336 | Args:
337 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
338 |
339 | Returns:
340 | List of webhooks for a specific form.
341 | """
342 |
343 | return self.fetch_url('/form/' + formID + '/webhooks', method='GET')
344 |
345 | def create_form_webhook(self, formID, webhookURL):
346 | """Add a new webhook
347 |
348 | Args:
349 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
350 | webhookURL (string): Webhook URL is where form data will be posted when form is submitted.
351 |
352 | Returns:
353 | List of webhooks for a specific form.
354 | """
355 |
356 | params = {'webhookURL': webhookURL}
357 |
358 | return self.fetch_url('/form/' + formID + '/webhooks', params, 'POST')
359 |
360 | def delete_form_webhook(self, formID, webhookID):
361 | """Delete a specific webhook of a form.
362 |
363 | Args:
364 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
365 | webhookID (string): You can get webhook IDs when you call /form/{formID}/webhooks.
366 |
367 | Returns:
368 | Remaining webhook URLs of form.
369 | """
370 |
371 | return self.fetch_url('/form/' + formID + '/webhooks/' + webhookID, None, 'DELETE')
372 |
373 | def get_submission(self, sid):
374 | """Get submission data
375 |
376 | Args:
377 | sid (string): You can get submission IDs when you call /form/{id}/submissions.
378 |
379 | Returns:
380 | Information and answers of a specific submission.
381 | """
382 |
383 | return self.fetch_url('/submission/' + sid, method='GET')
384 |
385 | def get_report(self, reportID):
386 | """Get report details
387 |
388 | Args:
389 | reportID (string): You can get a list of reports from /user/reports.
390 |
391 | Returns:
392 | Properties of a speceific report like fields and status.
393 | """
394 |
395 | return self.fetch_url('/report/' + reportID, method='GET')
396 |
397 | def get_folder(self, folderID):
398 | """Get folder details
399 |
400 | Args:
401 | folderID (string): Get a list of folders from /user/folders
402 |
403 | Returns:
404 | A list of forms in a folder, and other details about the form such as folder color.
405 | """
406 |
407 | return self.fetch_url('/folder/' + folderID, method='GET')
408 |
409 | def create_folder(self, folderProperties):
410 | """ Create a new folder
411 |
412 | Args:
413 | folderProperties (array): Properties of new folder.
414 |
415 | Returns:
416 | New folder.
417 | """
418 |
419 | return self.fetch_url('/folder', folderProperties, 'POST')
420 |
421 | def delete_folder(self, folderID):
422 | """Delete a specific folder and its subfolders
423 |
424 | Args:
425 | folderID (string): You can get a list of folders and its subfolders from /user/folders.
426 |
427 | Returns:
428 | Status of request.
429 | """
430 |
431 | return self.fetch_url('/folder/' + folderID, None, 'DELETE')
432 |
433 | def update_folder(self, folderID, folderProperties):
434 | """Update a specific folder
435 |
436 | Args:
437 | folderID (string): You can get a list of folders and its subfolders from /user/folders.
438 | folderProperties (json): New properties of the specified folder.
439 |
440 | Returns:
441 | Status of request.
442 | """
443 |
444 | return self.fetch_url('/folder/' + folderID, folderProperties, 'PUT')
445 |
446 | def add_forms_to_folder(self, folderID, formIDs):
447 | """Add forms to a folder
448 |
449 | Args:
450 | folderID (string): You can get the list of folders and its subfolders from /user/folders.
451 | formIDs (array): You can get the list of forms from /user/forms.
452 |
453 | Returns:
454 | Status of request.
455 | """
456 |
457 | formattedFormIDs = json.dumps({"forms": formIDs})
458 | return self.update_folder(folderID, formattedFormIDs)
459 |
460 | def add_form_to_folder(self, folderID, formID):
461 | """Add a specific form to a folder
462 |
463 | Args:
464 | folderID (string): You can get the list of folders and its subfolders from /user/folders.
465 | formID (string): You can get the list of forms from /user/forms.
466 |
467 | Returns:
468 | Status of request.
469 | """
470 |
471 | formattedFormID = json.dumps({"forms": [formID]})
472 | return self.update_folder(folderID, formattedFormID)
473 |
474 | def get_form_properties(self, formID):
475 | """Get a list of all properties on a form.
476 |
477 | Args:
478 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
479 |
480 | Returns:
481 | Form properties like width, expiration date, style etc.
482 | """
483 |
484 | return self.fetch_url('/form/' + formID + '/properties', method='GET')
485 |
486 | def get_form_property(self, formID, propertyKey):
487 | """Get a specific property of the form.
488 |
489 | Args:
490 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
491 | propertyKey (string): You can get property keys when you call /form/{id}/properties.
492 |
493 | Returns:
494 | Given property key value.
495 | """
496 |
497 | return self.fetch_url('/form/' + formID + '/properties/' + propertyKey, method='GET')
498 |
499 | def get_form_reports(self, formID):
500 | """Get all the reports of a form, such as excel, csv, grid, html, etc.
501 |
502 | Args:
503 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
504 |
505 | Returns:
506 | List of all reports in a form, and other details about the reports such as title.
507 | """
508 |
509 | return self.fetch_url('/form/' + formID + '/reports', method='GET')
510 |
511 | def create_report(self, formID, report):
512 | """Create new report of a form
513 |
514 | Args:
515 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
516 | report (array): Report details. List type, title etc.
517 |
518 | Returns:
519 | Report details and URL
520 | """
521 | return self.fetch_url('/form/' + formID + '/reports', report, 'POST')
522 |
523 | def delete_submission(self, sid):
524 | """Delete a single submission.
525 |
526 | Args:
527 | sid (string): You can get submission IDs when you call /form/{id}/submissions.
528 |
529 | Returns:
530 | Status of request.
531 | """
532 |
533 | return self.fetch_url('/submission/' + sid, None, 'DELETE')
534 |
535 | def edit_submission(self, sid, submission):
536 | """Edit a single submission.
537 |
538 | Args:
539 | sid (string): You can get submission IDs when you call /form/{id}/submissions.
540 | submission (array): New submission data with question IDs.
541 |
542 | Returns:
543 | Status of request.
544 | """
545 |
546 | sub = {}
547 |
548 | for key in submission.keys():
549 | if '_' in key and key != "created_at":
550 | sub['submission[' + key[0:key.find('_')] + '][' + key[key.find('_')+1:len(key)] + ']'] = submission[key]
551 | else:
552 | sub['submission[' + key + ']'] = submission[key]
553 |
554 | return self.fetch_url('/submission/' + sid, sub, 'POST')
555 |
556 | def clone_form(self, formID):
557 | """Clone a single form.
558 |
559 | Args:
560 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
561 |
562 | Returns:
563 | Status of request.
564 | """
565 | params = {"method": "post"}
566 |
567 | return self.fetch_url('/form/' + formID + '/clone', params, 'POST')
568 |
569 | def delete_form_question(self, formID, qid):
570 | """Delete a single form question.
571 |
572 | Args:
573 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
574 | qid (string): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
575 |
576 | Returns:
577 | Status of request.
578 | """
579 |
580 | return self.fetch_url('/form/' + formID + '/question/' + qid, None, 'DELETE')
581 |
582 | def create_form_question(self, formID, question):
583 | """Add new question to specified form.
584 |
585 | Args:
586 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
587 | question (array): New question properties like type and text.
588 |
589 | Returns:
590 | Properties of new question.
591 | """
592 | params = {}
593 |
594 | for key in question.keys():
595 | params['question[' + key + ']'] = question[key]
596 |
597 | return self.fetch_url('/form/' + formID + '/questions', params, 'POST')
598 |
599 | def create_form_questions(self, formID, questions):
600 | """Add new questions to specified form.
601 |
602 | Args:
603 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
604 | questions (json): New question properties like type and text.
605 |
606 | Returns:
607 | Properties of new question.
608 | """
609 |
610 | return self.fetch_url('/form/' + formID + '/questions', questions, 'PUT')
611 |
612 | def edit_form_question(self, formID, qid, question_properties):
613 | """Add or edit a single question properties.
614 |
615 | Args:
616 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
617 | qid (string): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
618 | question_properties (array): New question properties like type and text.
619 |
620 | Returns:
621 | Edited property and type of question.
622 | """
623 | question = {}
624 |
625 | for key in question_properties.keys():
626 | question['question[' + key + ']'] = question_properties[key]
627 |
628 | return self.fetch_url('/form/' + formID + '/question/' + qid, question, 'POST')
629 |
630 | def set_form_properties(self, formID, form_properties):
631 | """Add or edit properties of a specific form
632 |
633 | Args:
634 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
635 | form_properties (array): New properties like label width.
636 |
637 | Returns:
638 | Edited properties.
639 | """
640 | properties = {}
641 |
642 | for key in form_properties.keys():
643 | properties['properties[' + key + ']'] = form_properties[key]
644 |
645 | return self.fetch_url('/form/' + formID + '/properties', properties, 'POST')
646 |
647 | def set_multiple_form_properties(self, formID, form_properties):
648 | """Add or edit properties of a specific form
649 |
650 | Args:
651 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
652 | form_properties (json): New properties like label width.
653 |
654 | Returns:
655 | Edited properties.
656 | """
657 |
658 | return self.fetch_url('/form/' + formID + '/properties', form_properties, 'PUT')
659 |
660 | def create_form(self, form):
661 | """ Create a new form
662 |
663 | Args:
664 | form (array): Questions, properties and emails of new form.
665 |
666 | Returns:
667 | New form.
668 | """
669 |
670 | params = {}
671 |
672 | for key in form.keys():
673 | value = form[key]
674 | for k in value.keys():
675 | if (key == 'properties'):
676 | for k in value.keys():
677 | params[key + '[' + k + ']'] = value[k]
678 | else:
679 | v = value[k]
680 | for a in v.keys():
681 | params[key + '[' + k + '][' + a + ']'] =v[a]
682 |
683 | return self.fetch_url('/user/forms', params, 'POST')
684 |
685 | def create_forms(self, form):
686 | """ Create new forms
687 |
688 | Args:
689 | form (json): Questions, properties and emails of forms.
690 |
691 | Returns:
692 | New forms.
693 | """
694 |
695 | return self.fetch_url('/user/forms', form, 'PUT')
696 |
697 | def delete_form(self, formID):
698 | """Delete a specific form
699 |
700 | Args:
701 | formID (string): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
702 |
703 | Returns:
704 | Properties of deleted form.
705 | """
706 |
707 | return self.fetch_url('/form/' + formID, None, 'DELETE')
708 |
709 | def register_user(self, userDetails):
710 | """Register with username, password and email
711 |
712 | Args:
713 | userDetails (array): Username, password and email to register a new user
714 |
715 | Returns:
716 | New user's details
717 | """
718 |
719 | return self.fetch_url('/user/register', userDetails, 'POST')
720 |
721 | def login_user(self, credentials):
722 | """Login user with given credentials
723 |
724 | Args:
725 | credentials (array): Username, password, application name and access type of user
726 |
727 | Returns:
728 | Logged in user's settings and app key
729 | """
730 |
731 | return self.fetch_url('/user/login', credentials, 'POST')
732 |
733 | def logout_user(self):
734 | """Logout user
735 |
736 | Returns:
737 | Status of request
738 | """
739 |
740 | return self.fetch_url('/user/logout', method='GET')
741 |
742 | def get_plan(self, plan_name):
743 | """Get details of a plan
744 |
745 | Args:
746 | plan_name (string): Name of the requested plan. FREE, PREMIUM etc.
747 |
748 | Returns:
749 | Details of a plan
750 | """
751 |
752 | return self.fetch_url('/system/plan/' + plan_name, method='GET')
753 |
754 | def delete_report(self, reportID):
755 | """Delete a specific report
756 |
757 | Args:
758 | reportID (string): You can get a list of reports from /user/reports.
759 |
760 | Returns:
761 | Status of request.
762 | """
763 |
764 | return self.fetch_url('/report/' + reportID, None, 'DELETE')
765 |
--------------------------------------------------------------------------------