-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathJotForm.go
677 lines (573 loc) · 25.2 KB
/
JotForm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
// JotForm API - GO Client
// copyright 2013 Interlogy, LLC.
// link http://www.jotform.com
// version 1.0
// package JotFormAPI
package jotform
import (
"bytes"
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)
const baseURL = "http://api.jotform.com"
const apiVersion = "v1"
type jotformAPIClient struct {
apiKey string
outputType string
debugMode bool
}
func NewJotFormAPIClient(apiKey string, outputType string, debugMode bool) *jotformAPIClient {
client := &jotformAPIClient{apiKey, strings.ToLower(outputType), debugMode}
return client
}
func (client jotformAPIClient) GetOutputType() string { return client.outputType }
func (client *jotformAPIClient) SetOutputType(value string) { client.outputType = value }
func (client jotformAPIClient) GetDebugMode() bool { return client.debugMode }
func (client *jotformAPIClient) SetDebugMode(value bool) { client.debugMode = value }
func (client jotformAPIClient) debug(str interface{}) {
if client.debugMode {
fmt.Println(str)
}
}
func (client jotformAPIClient) executeHttpRequest(requestPath string, params interface{}, method string) []byte {
if client.outputType != "json" {
requestPath = requestPath + ".xml"
}
var path = baseURL + "/" + apiVersion + "/" + requestPath
client.debug(path)
var response *http.Response
var request *http.Request
var err error
client.debug(params)
if method == "GET" {
if params != "" {
data := params.(map[string]string)
values := make(url.Values)
for k, _ := range data {
values.Set(k, data[k])
}
path = path + "?" + values.Encode()
}
request, err = http.NewRequest("GET", path, nil)
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.Header.Add("apiKey", client.apiKey)
response, err = http.DefaultClient.Do(request)
} else if method == "POST" {
data := params.(map[string]string)
values := make(url.Values)
for k, _ := range data {
values.Set(k, data[k])
}
request, err = http.NewRequest("POST", path, strings.NewReader(values.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
request.Header.Add("apiKey", client.apiKey)
response, err = http.DefaultClient.Do(request)
} else if method == "DELETE" {
request, err = http.NewRequest("DELETE", path, nil)
request.Header.Add("apiKey", client.apiKey)
response, err = http.DefaultClient.Do(request)
} else if method == "PUT" {
parameters := params.([]byte)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
request, err = http.NewRequest("PUT", path, bytes.NewBuffer(parameters))
request.Header.Add("apiKey", client.apiKey)
response, err = http.DefaultClient.Do(request)
}
}
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
if client.outputType == "json" {
var f interface{}
json.Unmarshal(contents, &f)
result := f.(map[string]interface{})["content"]
content, err := json.Marshal(result)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
return content
}
} else if client.outputType == "xml" {
var f interface{}
xml.Unmarshal(contents, &f)
return contents
}
}
return nil
}
func createConditions(offset string, limit string, filter map[string]string, orderby string) map[string]string {
args := map[string]interface{}{
"offset": offset,
"limit": limit,
"filter": filter,
"orderby": orderby,
}
params := make(map[string]string)
for k, _ := range args {
if k == "filter" {
filterObj, err := json.Marshal(filter)
if err == nil {
params["filter"] = string(filterObj)
}
} else {
params[k] = args[k].(string)
}
}
return params
}
func createHistoryQuery(action string, date string, sortBy string, startDate string, endDate string) map[string]string {
args := map[string]string{
"action": action,
"date": date,
"sortBy": sortBy,
"startDate": startDate,
"endDate": endDate,
}
params := make(map[string]string)
for k, _ := range args {
if args[k] != "" {
params[k] = args[k]
}
}
return params
}
//GetUser
//Get user account details for a JotForm user.
//Returns user account type, avatar URL, name, email, website URL and account limits.
func (client jotformAPIClient) GetUser() []byte {
return client.executeHttpRequest("user", "", "GET")
}
//GetUsage
//Get number of form submissions received this month
//Returns number of submissions, number of SSL form submissions, payment form submissions and upload space used by user.
func (client jotformAPIClient) GetUsage() []byte {
return client.executeHttpRequest("user/usage", "", "GET")
}
//GetForms
//Get a list of forms for this account
//offset (string): Start of each result set for form list.
//limit (string): Number of results in each result set for form list.
//filter (map[string]string): Filters the query results to fetch a specific form range.
//orderBy (string): Order results by a form field name.
//Returns basic details such as title of the form, when it was created, number of new and total submissions.
func (client jotformAPIClient) GetForms(offset string, limit string, filter map[string]string, orderBy string) []byte {
var params = createConditions(offset, limit, filter, orderBy)
return client.executeHttpRequest("user/forms", params, "GET")
}
//GetSubmissions
//Get a list of submissions for this account
//offset (string): Start of each result set for form list.
//limit (string): Number of results in each result set for form list.
//filter (map[string]string): Filters the query results to fetch a specific form range.
//orderBy (string): Order results by a form field name.
//Returns basic details such as title of the form, when it was created, number of new and total submissions.
func (client jotformAPIClient) GetSubmissions(offset string, limit string, filter map[string]string, orderBy string) []byte {
var params = createConditions(offset, limit, filter, orderBy)
return client.executeHttpRequest("user/submissions", params, "GET")
}
//GetSubusers
//Get a list of sub users for this account
//Returns list of forms and form folders with access privileges.
func (client jotformAPIClient) GetSubusers() []byte {
return client.executeHttpRequest("user/subusers", "", "GET")
}
//GetFolders
//Get a list of form folders for this account
//Returns name of the folder and owner of the folder for shared folders.
func (client jotformAPIClient) GetFolders() []byte {
return client.executeHttpRequest("user/folders", "", "GET")
}
//GetReports
//List of URLS for reports in this account
//Returns reports for all of the forms. ie. Excel, CSV, printable charts, embeddable HTML tables.
func (client jotformAPIClient) GetReports() []byte {
return client.executeHttpRequest("user/reports", "", "GET")
}
//Update user's settings
//New user setting values with setting keys
//Returns changes on user settings
func (client jotformAPIClient) GetSettings() []byte {
return client.executeHttpRequest("user/settings", "", "GET")
}
//GetSettings
//Get user's settings for this account
//Returns user's time zone and language.
func (client jotformAPIClient) UpdateSettings(settings map[string]string) []byte {
return client.executeHttpRequest("user/settings", settings, "POST")
}
//GetHistory
//Get user activity log
//action (string): Filter results by activity performed. Default is 'all'.
//date (string): Limit results by a date range. If you'd like to limit results by specific dates you can use startDate and endDate fields instead.
//sortBy (string): Lists results by ascending and descending order.
//startDate (string): Limit results to only after a specific date. Format: MM/DD/YYYY.
//endDate (string): Limit results to only before a specific date. Format: MM/DD/YYYY.
//Returns activity log about things like forms created/modified/deleted, account logins and other operations.
func (client jotformAPIClient) GetHistory(action string, date string, sortBy string, startDate string, endDate string) []byte {
var params = createHistoryQuery(action, date, sortBy, startDate, endDate)
return client.executeHttpRequest("user/history", params, "GET")
}
//GetForm
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns form ID, status, update and creation dates, submission count etc.
func (client jotformAPIClient) GetForm(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10), "", "GET")
}
//GetFormQuestions
//Get a list of all questions on a form.
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns question properties of a form.
func (client jotformAPIClient) GetFormQuestions(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/questions", "", "GET")
}
//GetFormQuestion
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//qid (int): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
//Returns question properties like required and validation.
func (client jotformAPIClient) GetFormQuestion(formID int64, qid int) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/question/"+strconv.Itoa(qid), "", "GET")
}
//GetFormSubmission
//List of a form submissions.
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//offset (string): Start of each result set for form list.
//limit (string): Number of results in each result set for form list.
//filter (map[string]string): Filters the query results to fetch a specific form range.
//orderBy (string): Order results by a form field name.
//Returns submissions of a specific form.
func (client jotformAPIClient) GetFormSubmissions(formID int64, offset string, limit string, filter map[string]string, orderBy string) []byte {
var params = createConditions(offset, limit, filter, orderBy)
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/submissions", params, "GET")
}
//CreateFormSubmission
//Submit data to this form using the API
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//submission (map[string]string): Submission data with question IDs.
//Returns posted submission ID and URL.
func (client jotformAPIClient) CreateFormSubmission(formId int64, submission map[string]string) []byte {
data := make(map[string]string)
for k, _ := range submission {
if strings.Contains(k, "_") {
data["submission["+k[0:strings.Index(k, "_")]+"]["+k[strings.Index(k, "_")+1:len(k)]+"]"] = submission[k]
} else {
data["submission["+k+"]"] = submission[k]
}
}
return client.executeHttpRequest("form/"+strconv.FormatInt(formId, 10)+"/submissions", data, "POST")
}
//CreateFormSubmissions
//Submit data to this form using the API
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//submission (map[string]string): Submission data with question IDs.
//Returns posted submission ID and URL.
func (client jotformAPIClient) CreateFormSubmissions(formId int64, submission []byte) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formId, 10)+"/submissions", submission, "PUT")
}
//GetFormFiles
//List of files uploaded on a form
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns uploaded file information and URLs on a specific form.
func (client jotformAPIClient) GetFormFiles(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/files", "", "GET")
}
//GetFormWebhooks
//Get list of webhooks for a form
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns list of webhooks for a specific form.
func (client jotformAPIClient) GetFormWebhooks(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/webhooks", "", "GET")
}
//CreateFormWebhook
//Add a new webhook
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//webhookURL (string): Webhook URL is where form data will be posted when form is submitted.
//Returns list of webhooks for a specific form.
func (client jotformAPIClient) CreateFormWebhook(formId int64, webhookURL string) []byte {
params := map[string]string{
"webhookURL": webhookURL,
}
return client.executeHttpRequest("form/"+strconv.FormatInt(formId, 10)+"/webhooks", params, "POST")
}
//Delete a specific webhook of a form.
//Add a new webhook
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//webhookID (int64): You can get webhook IDs when you call /form/{formID}/webhooks.
//Returns remaining webhook URLs of form.
func (client jotformAPIClient) DeleteFormWebhook(formID int64, webhookID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/webhooks/"+strconv.FormatInt(webhookID, 10), nil, "DELETE")
}
//GetSubmission
//Get submission data
//sid (int64): You can get submission IDs when you call /form/{id}/submissions.
//Returns information and answers of a specific submission.
func (client jotformAPIClient) GetSubmission(sid int64) []byte {
return client.executeHttpRequest("user/submission/"+strconv.FormatInt(sid, 10), "", "GET")
}
//GetReport
//Get report details
//reportID (int64): You can get a list of reports from /user/reports.
//Returns properties of a speceific report like fields and status.
func (client jotformAPIClient) GetReport(reportID int64) []byte {
return client.executeHttpRequest("user/report/"+strconv.FormatInt(reportID, 10), "", "GET")
}
//GetFolder
//folderID (int64): You can get a list of folders from /user/folders.
//Returns a list of forms in a folder, and other details about the form such as folder color.
func (client jotformAPIClient) GetFolder(folderID string) []byte {
return client.executeHttpRequest("folder/"+folderID, "", "GET")
}
//CreateFolder
//folderProperties (map[string]string): Properties of new folder.
//Returns folder details.
func (client jotformAPIClient) CreateFolder(folderProperties map[string]string) []byte {
return client.executeHttpRequest("folder", folderProperties, "POST")
}
//DeleteFolder
//folderID (string): You can get the list of folders from /user/folders.
//Returns status of the request.
func (client jotformAPIClient) DeleteFolder(folderID string) []byte {
return client.executeHttpRequest("folder/"+folderID, nil, "DELETE")
}
//UpdateFolder
//folderID (string): You can get the list of folders from /user/folders.
//folderProperties ([]byte): Properties of folder.
//Returns status of the request.
func (client jotformAPIClient) UpdateFolder(folderID string, folderProperties []byte) []byte {
return client.executeHttpRequest("folder/"+folderID, folderProperties, "PUT")
}
//AddFormsToFolder
//folderID (string): You can get the list of folders from /user/folders.
//formIDs ([]string): You can get the list of forms from /user/forms.
//Returns status of the request.
func (client jotformAPIClient) AddFormsToFolder(folderID string, formIDs []string) []byte {
formattedFormIDs, err := json.Marshal(map[string][]string{
"forms": formIDs,
})
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
return client.executeHttpRequest("folder/"+folderID, formattedFormIDs, "PUT")
}
//AddFormToFolder
//folderID (string): You can get a list of folders from /user/folders.
//formID (string): You can get the list of forms from /user/forms.
//Returns status of the request.
func (client jotformAPIClient) AddFormToFolder(folderID string, formID string) []byte {
formattedFormID, err := json.Marshal(map[string][]string{
"forms": {formID},
})
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
return client.executeHttpRequest("folder/"+folderID, formattedFormID, "PUT")
}
//GetFormProperties
//Get a list of all properties on a form
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns form properties like width, expiration date, style etc.
func (client jotformAPIClient) GetFormProperties(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/properties", "", "GET")
}
//GetFormReports
//Get all the reports of a form, such as excel, csv, grid, html, etc.
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns list of all reports in a form, and other details about the reports such as title.
func (client jotformAPIClient) GetFormReports(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/reports", "", "GET")
}
//CreateReport
//Create new report of a form
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//report (map[string]string): Report details. List type, title etc.
//Returns report details and URL.
func (client jotformAPIClient) CreateReport(formID int64, report map[string]string) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/reports", report, "POST")
}
//GetFormProperty
//Get a specific property of the form.]
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//propertyKey (string): You can get property keys when you call /form/{id}/properties.
//Returns given property key value.
func (client jotformAPIClient) GetFormProperty(formID int64, propertyKey string) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/properties/"+propertyKey, "", "POST")
}
//DeleteSubmission
//Delete a single submission
//sid (int64): You can get submission IDs when you call /form/{id}/submissions.
//Returns status of request.
func (client jotformAPIClient) DeleteSubmission(sid int64) []byte {
return client.executeHttpRequest("submission/"+strconv.FormatInt(sid, 10), nil, "DELETE")
}
//EditSubmission
//Edit a single submission
//sid (int64): You can get submission IDs when you call /form/{id}/submissions.
//submission (map[string]string): New submission data with question IDs.
//Returns status of request.
func (client jotformAPIClient) EditSubmission(sid int64, submission map[string]string) []byte {
data := make(map[string]string)
for k, _ := range submission {
if strings.Contains(k, "_") && k != "created_at" {
data["submission["+k[0:strings.Index(k, "_")]+"]["+k[strings.Index(k, "_")+1:len(k)]+"]"] = submission[k]
} else {
data["submission["+k+"]"] = submission[k]
}
}
return client.executeHttpRequest("submission/"+strconv.FormatInt(sid, 10), data, "POST")
}
//CloneForm
//Clone a single form.
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns status of request.
func (client jotformAPIClient) CloneForm(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/clone", nil, "POST")
}
//DeleteFormQuestion
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//qid (int): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
//Returns status of request.
func (client jotformAPIClient) DeleteFormQuestion(formID int64, qid int) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/question/"+strconv.Itoa(qid), nil, "DELETE")
}
//CreateFormQuestion
//Add new question to specified form.
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//questionProperties (map[string]string): New question properties like type and text.
//Returns properties of new question.
func (client jotformAPIClient) CreateFormQuestion(formID int64, questionProperties map[string]string) []byte {
question := make(map[string]string)
for k, _ := range questionProperties {
question["question["+k+"]"] = questionProperties[k]
}
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/questions", question, "POST")
}
//CreateFormQuestion
//Add new question to specified form.
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//questions ([]byte): New question properties like type and text.
//Returns properties of new question.
func (client jotformAPIClient) CreateFormQuestions(formID int64, questions []byte) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/questions", questions, "PUT")
}
//EditFormQuestion
//Add or edit a single question properties
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//qid (int): Identifier for each question on a form. You can get a list of question IDs from /form/{id}/questions.
//questionProperties (map[string]string): New question properties like type and text.
//Returns edited property and type of question.
func (client jotformAPIClient) EditFormQuestion(formID int64, qid int, questionProperties map[string]string) []byte {
question := make(map[string]string)
for k, _ := range questionProperties {
question["question["+k+"]"] = questionProperties[k]
}
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/question/"+strconv.Itoa(qid), question, "POST")
}
//SetFormProperties
//Add or edit properties of a specific form
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//formProperties (map[string]string): New properties like label width.
//Returns edited properties.
func (client jotformAPIClient) SetFormProperties(formID int64, formProperties map[string]string) []byte {
properties := make(map[string]string)
for k, _ := range formProperties {
properties["properties["+k+"]"] = formProperties[k]
}
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/properties", properties, "POST")
}
//SetFormProperties
//Add or edit properties of a specific form
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//formProperties ([]byte): New properties like label width.
//Returns edited properties.
func (client jotformAPIClient) SetMultipleFormProperties(formID int64, formProperties []byte) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10)+"/properties", formProperties, "PUT")
}
//CreateForm
//Create a new form
//form ([]byte): Questions, properties and emails of new form.
//Returns new form.
func (client jotformAPIClient) CreateForm(form map[string]interface{}) []byte {
params := make(map[string]string)
for formKey, formValue := range form {
if formKey == "properties" {
properties := formValue
for properyKey, propertyValue := range properties.(map[string]string) {
params[formKey+"["+properyKey+"]"] = propertyValue
}
} else {
formItem := formValue
for formItemKey, formItemValue := range formItem.(map[string]interface{}) {
item := formItemValue
for itemKey, itemValue := range item.(map[string]string) {
params[formKey+"["+formItemKey+"]["+itemKey+"]"] = itemValue
}
}
}
}
return client.executeHttpRequest("user/forms", params, "POST")
}
//Create new forms
//Create a new form
//form ([]byte): Questions, properties and emails of forms.
//Returns new forms.
func (client jotformAPIClient) CreateForms(form []byte) []byte {
return client.executeHttpRequest("user/forms", form, "PUT")
}
//DeleteForm
//formID (int64): Form ID is the numbers you see on a form URL. You can get form IDs when you call /user/forms.
//Returns properties of deleted form.
func (client jotformAPIClient) DeleteForm(formID int64) []byte {
return client.executeHttpRequest("form/"+strconv.FormatInt(formID, 10), nil, "DELETE")
}
//RegisterUser
//Register with username, password and email
//userDetails (map[string]string): Username, password and email to register a new user
//Returns new user's details
func (client jotformAPIClient) RegisterUser(userDetails map[string]string) []byte {
return client.executeHttpRequest("user/register", userDetails, "POST")
}
//LoginUser
//Login user with given credentials
//credentials (map[string]string): Username, password, application name and access type of user
//Returns logged in user's settings and app key
func (client jotformAPIClient) LoginUser(credentials map[string]string) []byte {
return client.executeHttpRequest("user/login", credentials, "POST")
}
//LogoutUser
//Logout user
//Returns status of request
func (client jotformAPIClient) LogoutUser() []byte {
return client.executeHttpRequest("user/logout", "", "GET")
}
//GetPlan
//Get details of a plan
//planName (string): Name of the requested plan. FREE, PREMIUM etc.
//Returns details of a plan
func (client jotformAPIClient) GetPlan(planName string) []byte {
return client.executeHttpRequest("system/plan/"+planName, "", "GET")
}
//DeleteReport
//reportID (int64): You can get a list of reports from /user/reports.
//Returns status of request.
func (client jotformAPIClient) DeleteReport(reportID int64) []byte {
return client.executeHttpRequest("report/"+strconv.FormatInt(reportID, 10), nil, "DELETE")
}