-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiary.apib
687 lines (505 loc) · 19.7 KB
/
apiary.apib
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
678
679
680
681
682
683
684
685
686
687
FORMAT: 1A
HOST: https://jak-zhubnout-dieta.cz/
# Naturhouse API v2
## Data Structures
### `OAuth grant request` (object)
+ `grant_type`: `password` (string, required)
+ `client_id`: `1_611yogt6e8sgwg0c8cogs4sooo0skw8c4400404ck0cowgcg0g` (string, required)
+ `client_secret`: `5thhvnqv8uwwcgcc0gwg4k08wsw8cosgkwk0woksc8www4044` (string, required)
+ `username`: `demo` (string, optional)
+ `password`: `demo` (string, optional)
### `OAuth jwt-bearer grant request` (object)
+ `grant_type`: `urn:ietf:params:oauth:grant-type:jwt-bearer` (string, required)
+ assertion: `eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ` (string, required)
### `OAuth valid response` (object)
+ `access_token`: `eyJhbGciOiJIUzI1NiJ9.e30.XmNK3GpH3Ys_7wsYBfq4C3M6goz71I7dTgUkuIa5lyQ` (string, required) - valid JWT
+ scope: null
+ `expires_in`: 3600 (number, required)
+ `token_type`: bearer (string, required)
+ `refresh_token`: `NzNmMDJkODFlNDk3N2YwOTZkMzhlZGNjNjBlMzMzMjNjOTkyZDI1YTU5ODQyMGNiYjk3YjM2OGFiYzM2ZGQzYQ`
### PackageItem
+ id: `1` (number) - Unique id of package
+ name: `Balicek` (string) - Package name
+ total_price: `100.0` (number) - float price VAT included
+ formatted_price: `100,00 Kč` (string) - formatted price including VAT and currency
### PackageList
+ packages (array[PackageItem])
### Package
+ package_id: `1` (number)
+ paid: `true` (boolean)
### Contact
+ fname: `test` (string, required) - First name
+ lname: `test` (string, required) - Last name
+ phone: `0777777777` (string, required) - Phone (format XXXXXXXXX or +XXXXXXXXXXXX without spaces) by default prefix +420 is added
+ email: `[email protected]` (string, required) - Email (email has validation just for format)
+ branch: `87` (number, required) - Branch id from list of branches
+ call_time: `1` (optional) - Contact time ID
+ zip: `11000` (optional) - ZIP code
+ packages (array[Package], fixed)
+ (object)
+ package_id: 4 (number)
+ paid: false (boolean)
+ interest: `-1` (optional, enum) - contact intent to
+ `-1` - reduce weight
+ `0` - stabelization of weight
+ `1` - increasing weight
+ source: `1` (optional, number) - contact source (Elevated permissions required)
+ verified: `1` (optional, number) - Contact phone is verified by SMS
+ sex: `0` (enum, optional) - sex
+ `0` - male
+ `1` - female
+ yob: `1982` (optional, number) - year of birth
+ weight: `150` (optional, number) - contact weight [kg]
+ target_weight: `55` (optional, number) - target weight [kg]
+ height: `155` (optional, number) - height [cm]
+ job: `programmer` (string) - job
+ health: `bad` (string) - contact health
+ activities: `none` (string) - contact activities (like sports, free time...)
+ utm_medium: `none` (optional, string) - utm medium
+ utm_term: `none` (optional, string) - utm term
+ utm_content: `none` (optional, string) - utm content (is suitable for stats)
+ utm_campaign: `none` (optional, string) - utm campaign (is suitable for stats)
+ note: `note for call operator` (optional, string) - custom note
###201Created
+ message: `new client created` (string)
+ contact_id: `1234` (number)
###304NotModified
+ message: `contact already exists` (string)
+ contact_id: `1234` (number)
### 401MissingToken
+ message: `authorization token is missing` (string)
### 403InvalidToken
+ message: `invalid token` (string)
### 404NotFound
+ message: `contact_id not found` (string)
+ receipt_id: `1234` (number)
## Authorization & Authentification [/api/v2/token]
The Naturhouse API uses [OAuth 2.0](http://oauth.net/2/) for authentication or `X-Auth-Token` static token provided by administrator. Static token requres allowed client IP.
### Acces Token Request [POST]
+ Request
+ Attributes (OAuth grant request)
+ Body
{
"grant_type": "password",
"client_id": "1_611yogt6e8sgwg0c8cogs4sooo0skw8c4400404ck0cowgcg0g",
"client_secret": "5thhvnqv8uwwcgcc0gwg4k08wsw8cosgkwk0woksc8www4044",
"username":"demo",
"password": "demo"
}
+ Response 200 (application/json)
+ Attributes (OAuth valid response)
+ Request
+ Attributes (OAuth jwt-bearer grant request)
+ Response 200 (application/json)
+ Attributes (OAuth valid response)
+ Response 400 (application/json)
400 Bad request
List of error codes
| Error Descriptions |
| ---------------------------------------------------|
| Invalid grant_type parameter or parameter missing |
| The client credentials are invalid |
| Invalid username and password combination |
+ Body
{
"error": "invalid_request",
"error_description": "Invalid grant_type parameter or parameter missing"
}
+ Response 403 (application/json)
403 Invalid credentials
## Branches [/api/v2/branches]
Returns list of Naturhouse branches. Unique branch id is required for successful contact creation.
### List of branches [GET /api/v2/branches{?active}]
+ Parameters
+ active: `0` (optional, number) - all active branches
+ 0 - all active branches
+ 1 - only active branches with positive credit
+ 2 - all branches, inactive included (discuss this usage with responsible person)
+ Response 200 (application/json)
+ Headers
X-Total-Count: 3
+ Body
{
"branches":
[
{
"id": "3",
"new_contract": "1",
"sections": "1",
"region": "Hlavní město Praha",
"name": "Praha 3 - Flora",
"person": "Martina Divišová",
"company_name": "NATURHOUSE - Chrudimská",
"email": "[email protected]",
"phone": "604 703 005",
"full": "0",
"city": "Praha 3",
"street": "Chrudimská 7",
"zip": "13000",
"color": "#78D958",
"lat": "50.0772793",
"lon": "14.4620468"
},
{
"id": "4",
"new_contract": "1",
"sections": "1",
"region": "Liberecký kraj",
"name": "Turnov",
"person": "Lenka Tomčo",
"company_name": "NATURHOUSE - Turnov",
"email": "[email protected]",
"phone": "488 578 801",
"full": "0",
"city": "Turnov",
"street": "Hluboká 280",
"zip": "51101",
"color": "#78D958",
"lat": "50.587285",
"lon": "15.1568091"
},
{
"id": "5",
"new_contract": "0",
"sections": "1",
"region": "Jihomoravský kraj",
"name": "Brno - OC Olympie",
"person": null,
"company_name": "NATURHOUSE - Brno Olympie",
"email": "[email protected]",
"phone": "513 033 029",
"full": "0",
"city": "Modřice, Brno",
"street": "U dálnice 777",
"zip": "66442",
"color": "#78D958",
"lat": "49.1950602",
"lon": "16.6068371"
}
]
}
+ Response 500 (text/plain)
500 Server error
+ Body
+ Response 520 (text/plain)
520 Unknown error
+ Body
+ Response 524 (text/plain)
524 Server side timeout
+ Body
## Contact Times [/api/v2/contacttimes]
<a name="contacttimes"></a>
This is list of possible values for ```call_time``` field in contact creation.
### List of Contact Times [GET]
+ Response 200 (application/json)
+ Headers
X-Total-Count: 3
+ Body
{
"times": [
{
"id": 0,
"text": "kdykoli"
},
{
"id": 8,
"text": "dopoledne"
},
{
"id": 9,
"text": "odpoledne"
}
]
}
## Packages [/api/v2/packages]
Returns list of Naturhouse available packages.
### List of packages [GET /api/v2/packages]
+ Response 200 (application/json)
+ Attributes(PackageList)
+ Headers
X-Total-Count: 5
+ Body
{
"packages":
[
{
"id": 1,
"name": "Chci ploché břicho!",
"total_price": 1626.0,
"formatted_price": "1 626,00 Kč"
},
{
"id": 2,
"name": "Chci ploché břicho! - řešení pro muže",
"total_price": 1605.0,
"formatted_price": "1 605,00 Kč"
},
{
"id": 3,
"name": "Lehké nohy",
"total_price": 1435.0,
"formatted_price": "1 435,00 Kč"
},
{
"id": 4,
"name": "Hubnutí a detoxikace",
"total_price": 1659.0,
"formatted_price": "1 659,00 Kč"
},
{
"id": 5,
"name": "Sbohem, celulitido!",
"total_price": 1457.0,
"formatted_price": "1 457,00 Kč"
},
]
}
+ Response 500 (text/plain)
500 Server error
+ Body
+ Response 520 (text/plain)
520 Unknown error
+ Body
+ Response 524 (text/plain)
524 Server side timeout
+ Body
## Contact [/api/v2/contact]
### Create new contact [POST]
+ Request
+ Header
Authorization: Bearer <access-token>
X-Auth-Token: cG9sZ2FyaT
+ Body
{
"fname": "Jmeno",
"lname": "Prijmeni",
"phone": "777111222",
"email": "[email protected]",
"packages": [
{
"package_id": 1,
"paid": true
},
{
"package_id": 4,
"paid": false
}
],
"branch": 3
}
+ Attributes (Contact)
+ Response 201 (application/json)
+ Attributes (201Created)
+ Response 304 (application/json)
304 Response sent when the identical contact already exists
+ Attributes (304NotModified)
+ Request
+ Header
Authorization: Bearer <access-token>
X-Auth-Token: cG9sZ2FyaT
+ Body
{
"fname": "Jmeno",
"lname": "Prijmeni"
}
+ Response 400 (application/json)
400 Missing or invalid data, complete request will be saved to the error log
List of error codes
| Code | Requeue | Note
| --------- | ---------- | -----------------------------
| 1 | NO | Invalid input data, check JSON format please
| 10 | NO | Missing required field
| 11 | NO | Invalid phone format
| 12 | NO | Invalid email format
| 13 | NO | Invalid call time id
| 14 | NO | Invalid branch id
| 15 | NO | Invalid ZIP format
| 16 | NO | Invalid Interest format
| 17 | NO | Invalid Sex format
| 18 | NO | Invalid Source format
| 20 | NO | Branch is not exist or is not active
| 21 | NO | Branch ID must be set if contact verified is 1
| 100 | NO | Exactly the same contact already exists
+ Body
{
"errors":
[
{
"code": 10,
"field": "phone",
"message": "Missing required field"
},
{
"code": 10,
"field": "email",
"message": "Missing required field"
},
{
"code": 10,
"field": "branch",
"message": "Missing required field"
},
{
"code": 11,
"field": "phone",
"message": "Invalid phone format"
},
{
"code": 12,
"field": "email",
"message": "Invalid email format"
}
]
}
+ Response 401 (application/json)
401 Response sent when the Token is Missing
+ Attributes (401MissingToken)
+ Response 403 (application/json)
403 Response sent when the token sent is invalid
+ Attributes (403InvalidToken)
+ Response 500 (text/plain)
500 Server error
+ Body
+ Response 520 (text/plain)
520 Unknown error
+ Body
+ Response 524 (text/plain)
524 Server side timeout
+ Body
### Get Contact [GET /api/v2/contact{?id}]
#### Contact status - possible values
| Contact status | Note
| --------------- | ---------------------------------------------
| new | New client (not evaluated yet)
| bussy | Client not responding to phone calls |
| valid | Ordered client
| discard | The Client is not interested
| finished | The Client with completed procedure
| refund_request | Request to Client reclamation
| refund | Reclamated contact
+ Parameters
+ id: `1234` (required, number) - contact id
+ Request
+ Header
Authorization: Bearer <access-token>
X-Auth-Token: cG9sZ2FyaT
+ Response 200 (application/json)
+ Body
{
"id": "167312",
"state": "valid",
"first_visit_from": "2017-04-23T12:00:00.511Z",
"first_visit_to": "2017-04-23T12:15:00.511Z",
"first_visit_visited": 0,
"reordered": "0",
"note": "",
"full_name": "Jmeno Prijmeni",
"created": "2017-04-22T18:25:43.511Z",
"last_modified": "2017-04-23T18:25:43.511Z"
}
+ Response 400 (application/json)
400 Missing or invalid parameters
| Code | Requeue | Note |
| --------- | ---------- | ----------------------------------------------------------------------------- |
| 10 | NO | Missing required attribute |
| 11 | NO | Invalid datetime format |
| 12 | NO | From is greater or equal like To |
+ Body
{
"errors":
[
{
"code": 10,
"message": "Missing required attribute"
}
]
}
+ Response 404 (application/json)
404 Response sent when contact id not found
+ Body
{
"message": "Contact ID not found"
}
+ Response 401 (application/json)
401 Response sent when the Token is Missing
+ Attributes (401MissingToken)
+ Response 403 (application/json)
403 Response sent when the token sent is invalid
+ Attributes (403InvalidToken)
+ Response 500 (text/plain)
500 Server error
+ Body
+ Response 520 (text/plain)
520 Unknown error
+ Body
+ Response 524 (text/plain)
524 Server side timeout
+ Body
## Contacts [/api/v2/contacts]
### Get list of contacts [GET /api/v2/contacts{?lastModified}{?createdFrom,createdTo}{?page}{?limit}]
This endpoint will provide only contacts related to API credentials.
```lastModified``` or ```createdFrom + createdTo``` range is required.
+ Parameters
+ lastModified: `2017-04-23T18:25:43.511Z` (string) - last modified date (the return will contain contacts modified after this datetime)
+ createdFrom: `2017-04-22T18:25:43.511Z` (string)
+ createdTo: `2017-04-25T18:25:43.511Z` (string)
+ page: `1` (optional, number) - page of result
+ limit: `50` (optional, number) - limit results
+ Request
+ Header
Authorization: Bearer <access-token>
X-Auth-Token: cG9sZ2FyaT
+ Response 200 (application/json)
+ Header
X-Total-Count: 1
X-Pages: 1
X-Page: 1
+ Body
{
"contacts": [
{
"id": "167312",
"state": "valid",
"first_visit_from": "2017-04-23T12:30:00.511Z",
"first_visit_to": "2017-04-23T12:45:00.511Z",
"first_visit_visited": 0,
"reordered": "0",
"note": "",
"full_name": "Jmeno Prijmeni",
"created": "2017-04-22T18:25:43.511Z",
"last_modified": "2017-04-22T19:25:43.511Z"
}
]
}
+ Response 400 (application/json)
400 Missing or invalid parameters
| Code | Requeue | Note |
| --------- | ---------- | ----------------------------------------------------------------------------- |
| 10 | NO | Missing required attribute |
| 11 | NO | Invalid datetime format |
| 12 | NO | From is greater or equal like To |
+ Body
{
"errors":
[
{
"code": 10,
"message": "Missing required attribute"
}
]
}
+ Response 401 (application/json)
401 Response sent when the Token is Missing
+ Attributes (401MissingToken)
+ Response 403 (application/json)
403 Response sent when the token sent is invalid
+ Attributes (403InvalidToken)
+ Response 500 (text/plain)
500 Server error
+ Body
+ Response 520 (text/plain)
520 Unknown error
+ Body
+ Response 524 (text/plain)
524 Server side timeout
+ Body