UNPKG

1.69 kBJavaScriptView Raw
1const request = require('request-promise')
2class Form {
3 constructor(client) {
4 this.client = client
5 }
6
7 getAll(options) {
8 return this.get(options)
9 }
10
11 get(options) {
12 return this.client._request({
13 method: 'GET',
14 path: '/forms/v2/forms',
15 qs: options,
16 })
17 }
18
19 getById(guid) {
20 return this.client._request({
21 method: 'GET',
22 path: `/forms/v2/forms/${guid}`,
23 })
24 }
25
26 getFields(guid) {
27 return this.client._request({
28 method: 'GET',
29 path: `/forms/v2/fields/${guid}`,
30 })
31 }
32
33 getSingleField(guid, fieldName) {
34 return this.client._request({
35 method: 'GET',
36 path: `/forms/v2/fields/${guid}/${fieldName}`,
37 })
38 }
39
40 getSubmissions(guid, options) {
41 return this.client._request({
42 method: 'GET',
43 path: `/form-integrations/v1/submissions/forms/${guid}`,
44 qs: options,
45 })
46 }
47
48 submit(portalId, formId, data) {
49 return request({
50 json: true,
51 headers: { 'Content-Type': 'application/json' },
52 method: 'POST',
53 url: `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`,
54 body: data,
55 })
56 }
57
58 create(data) {
59 return this.client._request({
60 method: 'POST',
61 path: '/forms/v2/forms',
62 body: data,
63 })
64 }
65
66 update(guid, data) {
67 return this.client._request({
68 method: 'PUT',
69 path: `/forms/v2/forms/${guid}`,
70 body: data,
71 })
72 }
73
74 delete(guid) {
75 return this.client._request({
76 method: 'DELETE',
77 path: `/forms/v2/forms/${guid}`,
78 })
79 }
80
81 getUploadedFileByUrl(url) {
82 return request({
83 method: 'GET',
84 url: url,
85 })
86 }
87}
88
89module.exports = Form