-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2025.02.21_engineering_nocoDB.mdc
More file actions
1562 lines (1118 loc) · 69.1 KB
/
Copy path2025.02.21_engineering_nocoDB.mdc
File metadata and controls
1562 lines (1118 loc) · 69.1 KB
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Overview REST APIs
Once you've created the schemas, you can manipulate the data or invoke actions using the REST APIs. We provide several types of APIs for different usages. Refer to the following links for more details:
- [Meta APIs](https://meta-apis-v2.nocodb.com/)
- [Data APIs](https://data-apis-v2.nocodb.com/)
You will need an API key and endpoint to use the API. The endpoint URL for hosted instances of NocoDB is in the format `https://app.nocodb.com/api/v2/tables/TABLEID/records` and `https://app.nocodb.com/api/v2/meta/bases/BASEID/info`.
- You can find a TABLEID by going to any table in NocoDB > Details > API Snippets.
- You can find your BASEID by clicking the menu icon next to any database, rest APIs > and seeing the BASEID in the url.
Additional information on the REST APIs is provided below.
## Query params
| Name | Alias | Use case | Default value | Example value |
|--------|-------|--------------------------------|---------------|-------------------------------------------------------------------------------------------------------------|
| where | w | Complicated where conditions | | `(colName,eq,colValue)~or(colName2,gt,colValue2)`<br>Usage: Comparison operators<br>Usage: Logical operators |
| limit | l | Number of rows to get | 10 | 20 |
| offset | o | Offset for pagination | 0 | 20 |
| sort | s | Sort by column name | | column_name |
| fields | f | Required column names in result| * | column_name1,column_name2 |
| shuffle| r | Shuffle the result for pagination | 0 | 1 (Only allow 0 or 1. Other values would see it as 0) |
## Comparison Operators
| Operation | Meaning | Example |
|-----------|-------------|-------------------------------|
| eq | equal | (colName,eq,colValue) |
| neq | not equal | (colName,neq,colValue) |
| not | not equal | (colName,not,colValue) |
| gt | greater than| (colName,gt,colValue) |
| ge | greater or equal | (colName,ge,colValue) |
| lt | less than | (colName,lt,colValue) |
| le | less or equal | (colName,le,colValue) |
| is | is | (colName,is,true/false/null) |
| isnot | is not | (colName,isnot,true/false/null) |
| in | in | (colName,in,val1,val2,val3,val4) |
| btw | between | (colName,btw,val1,val2) |
| nbtw | not between | (colName,nbtw,val1,val2) |
| like | like | (colName,like,%name) |
| nlike | not like | (colName,nlike,%name) |
| isWithin | is Within (Available in `Date` and `DateTime` only) | (colName,isWithin,sub_op) |
| allof | includes all of | (colName,allof,val1,val2,...) |
| anyof | includes any of | (colName,anyof,val1,val2,...) |
| nallof | does not include all of (includes none or some, but not all of) | (colName,nallof,val1,val2,...) |
| nanyof | does not include any of (includes none of) | (colName,nanyof,val1,val2,...) |
## Comparison Sub-Operators
The following sub-operators are available in the `Date` and `DateTime` columns.
| Operation | Meaning | Example |
|------------------|-------------------|---------------------------------|
| today | today | (colName,eq,today) |
| tomorrow | tomorrow | (colName,eq,tomorrow) |
| yesterday | yesterday | (colName,eq,yesterday) |
| oneWeekAgo | one week ago | (colName,eq,oneWeekAgo) |
| oneWeekFromNow | one week from now | (colName,eq,oneWeekFromNow) |
| oneMonthAgo | one month ago | (colName,eq,oneMonthAgo) |
| oneMonthFromNow | one month from now| (colName,eq,oneMonthFromNow) |
| daysAgo | number of days ago| (colName,eq,daysAgo,10) |
| daysFromNow | number of days from now | (colName,eq,daysFromNow,10) |
| exactDate | exact date | (colName,eq,exactDate,2022-02-02) |
For `isWithin` in `Date` and `DateTime` columns, the different set of sub-operators are used.
| Operation | Meaning | Example |
|--------------------|---------------------|-----------------------------------|
| pastWeek | the past week | (colName,isWithin,pastWeek) |
| pastMonth | the past month | (colName,isWithin,pastMonth) |
| pastYear | the past year | (colName,isWithin,pastYear) |
| nextWeek | the next week | (colName,isWithin,nextWeek) |
| nextMonth | the next month | (colName,isWithin,nextMonth) |
| nextYear | the next year | (colName,isWithin,nextYear) |
| nextNumberOfDays | the next number of days | (colName,isWithin,nextNumberOfDays,10) |
| pastNumberOfDays | the past number of days | (colName,isWithin,pastNumberOfDays,10) |
## Logical Operators
| Operation | Example |
|-----------|-------------------------------------------------------------------------|
| ~or | (checkNumber,eq,JM555205)~or((amount,gt,200)~and(amount,lt,2000)) |
| ~and | (checkNumber,eq,JM555205)~and((amount,gt,200)~and(amount,lt,2000)) |
| ~not | ~not(checkNumber,eq,JM555205) |
# Upload via API
Sample code to upload files via API is listed below. Assumes `http://localhost:8080/` as the base URL for the API calls.
## Upload local file
```
let axios = require("axios").default;
let FormData = require('form-data');
let fs = require('fs');
// Configurations
//
const project_id = '<Project Identifier>';
const table_id = '<Table Identifier>';
const xc_token = '<Auth Token>';
const file_path = '<Local File Path>';
// Insert Image
// @param image_path : local file path
// @return : JSON object to be used in insert record API for attachment field
//
async function insertImage (path) {
const formData = new FormData();
formData.append("file", fs.createReadStream(path));
const data = await axios({
url: 'http://localhost:8080/api/v2/storage/upload',
data: formData,
headers:{
'Content-Type':`multipart/form-data;`,
'xc-token': xc_token
},
method: 'post',
// Optional : storage file path
params: {"path": "somePath"}
});
return data;
}
// Insert record with attachment
// Assumes a table with two columns :
// 'Title' of type SingleLineText and
// 'Attachment' of type Attachment
//
async function uploadFileExample() {
let response = await insertImage(file_path);
let row = {
"Title": "2",
"Attachment": response.data
};
await axios({
method: 'POST',
url: `http://localhost:8080/api/v2/tables/${table_id}/records`,
data: row,
headers: {
'xc-token': xc_token
}
});
}
(async () => {
await uploadFileExample();
})();
```
## Upload via URL
```
let axios = require("axios").default;
let FormData = require('form-data');
let fs = require('fs');
// Configurations
//
const project_id = '<Project Identifier>';
const table_id = '<Table Identifier>';
const xc_token = '<Auth Token>';
// URL array : URLs of files to be uploaded
const URLs = [{ url: '<URL1>' }, { url: '<URL2>' }];
// Insert Image
// @param URLs : [] containing public URL for files to be uploaded
// @return : JSON object to be used in insert record API for attachment field
//
async function insertImageByURL (URL_array) {
const data = await axios({
url: 'http://localhost:8080/api/v2/storage/upload-by-url',
data: URL_array,
headers: {
'xc-token': xc_token
},
method: 'post',
// Optional : storage file path
params: {"path": "somePath"}
});
return data;
}
// Insert record with attachment
// Assumes a table with two columns :
// 'Title' of type SingleLineText and
// 'Attachment' of type Attachment
//
async function uploadByUrlExample() {
let response = await insertImageByURL(URLs);
// Update two columns : Title and Attachment
let row = {
"Title": "3",
"Attachment": response.data
};
await axios({
method: 'POST',
url: `http://localhost:8080/api/v2/tables/${table_id}/records`,
data: row,
headers: {
'xc-token': xc-token
}
});
}
(async () => {
await uploadByUrlExample();
})();
```
# Accessing APIs
## API Tokens[](https://docs.nocodb.com/developer-resources/rest-APIs/accessing-apis#api-tokens "Direct link to API Tokens")
NocoDB APIs can be authorized by using API Tokens. API tokens allow us to integrate seamlessly with 3rd party apps. See [API Tokens Management](https://docs.nocodb.com/account-settings/api-tokens) for more.
### Create API Token[](https://docs.nocodb.com/account-settings/api-tokens/#create-api-token "Direct link to Create API Token")
Open Account Settings page from the user menu in the bottom left corner of the sidebar.
1. Click on `User menu` in the bottom left corner of the sidebar,
2. Select `Account Settings` from the dropdown

Follow the steps below to create API Token
1. Click on `Tokens` tab in the `Account Settings` page
2. Click on `Add New API Token`
3. Enter the name for the API Token
4. Click on `Save` button to save the changes
5. Copy the API Token by clicking on `Copy` button displayed under `Actions` menu
6. Use the API Token in the services that require it to authenticate as `xc-token` in the headers.
```
{ "headers": { "xc-token": "Copied API token here under quotes" }}
```


info
- Only one token can be created per user
- API Token does not expire, but it can be deleted anytime.
API Token created will get added to the list. Copy API token by clicking on `Copy` button displayed under `Actions` menu

### Delete API Token[](https://docs.nocodb.com/account-settings/api-tokens/#delete-api-token "Direct link to Delete API Token")
warning
Note that, all the services using the API Token will stop working once the API Token is deleted.
Open Account Settings page from the user menu in the bottom left corner of the sidebar.
1. Click on `User menu` in the bottom left corner of the sidebar,
2. Select `Account Settings` from the dropdown

1. Click on `Tokens` tab in the `Account Settings` page
2. From the `Actions` menu, click on `Delete` button associated with the API Token to be deleted

## Swagger UI (Actions on base)[](https://docs.nocodb.com/developer-resources/rest-APIs/accessing-apis#swagger-ui "Direct link to Swagger UI")
You can interact with the API's resources via the Swagger UI. For more details, see [Swagger APIs Doc](https://docs.nocodb.com/bases/actions-on-base#rest-apis)
### Base context menu[](https://docs.nocodb.com/bases/actions-on-base/#base-context-menu "Direct link to Base context menu")
The base context menu offers a selection of swift actions that can be executed on a base. To access this menu, click on the ellipsis symbol (`...`) located adjacent to the base name within the left sidebar. 
### Rename base[](https://docs.nocodb.com/bases/actions-on-base/#rename-base "Direct link to Rename base")
To modify the name of a base, you can easily do so by following these steps:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Rename` option.
3. Input the new name for the base directly within the field provided and then press the `Enter` key to confirm and save the updated name.


### Star base[](https://docs.nocodb.com/bases/actions-on-base/#star-base "Direct link to Star base")
You can star a base by following simple steps below:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Add to Starred` option.
3. Subsequently, the designated base will be placed into the "Starred" section, conveniently positioned within the left sidebar.


info
Starred base will appear in the `Starred` section on the left sidebar.
#### Remove a base from starred list[](https://docs.nocodb.com/bases/actions-on-base/#remove-a-base-from-starred-list "Direct link to Remove a base from starred list")
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Remove from Starred` option.
3. Subsequently, the designated base will be removed from the `Starred` section.

### Duplicate base[](https://docs.nocodb.com/bases/actions-on-base/#duplicate-base "Direct link to Duplicate base")
To duplicate a base, you can follow these straightforward steps:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Duplicate` option.
3. Optionally, you can configure the duplication process with the following choices: a) `Include data`: You have the flexibility to choose whether to duplicate the base with or without its data. b) `Include views`: You can decide whether to duplicate the base with or without its views.
4. Click the `Confirm` button in the confirmation modal that pops up.
5. A new base will be created, mirroring the original base's schema and data/views based on the configurations specified in step 3.


info
- A duplicate base will be generated within the same workspace as the original base.
- The duplicated base will be suffixed with `Copy` in its name.
- You will be designated as the `base owner` upon the duplication of the base.
- Existing base members will not be transferred to the duplicated base.
### Delete base[](https://docs.nocodb.com/bases/actions-on-base/#delete-base "Direct link to Delete base")
If you determine that a base is no longer necessary, you have the option to permanently remove it from your workspace. Deleting a base will delete all the tables and data associated with it.
info
**This action cannot be undone.**
info
Only **base owner** can delete a workspace.
To delete a base:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Delete` option.
3. Select `Delete base` button on the confirmation dialog box.


### Developer features[](https://docs.nocodb.com/bases/actions-on-base/#developer-features "Direct link to Developer features")
#### Base settings[](https://docs.nocodb.com/bases/actions-on-base/#base-settings "Direct link to Base settings")
Some general configurations are available for you to modify within the base settings.
1. **Show M2M tables**: Toggle this option to display/hide M2M tables within the left sidebar. Many-to-many relation is supported via a junction table & is hidden by default.
2. **Show NULL in cells**: Toggle this option to display/hide NULL values within the cells of the table. This helps differentiate against cells holding EMPTY string.
3. **Show NULL & Empty in Filters**: Enable 'additional' filters to differentiate fields containing NULL & Empty Strings. Default support for Blank treats both NULL & Empty strings alike.
To configure base settings, you can follow these steps:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Settings` option.


#### REST APIs[](https://docs.nocodb.com/bases/actions-on-base/#rest-apis "Direct link to REST APIs")
NocoDB provides a Swagger UI for each base. To access the Swagger UI, follow these steps:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `REST APIs` option.


#### Relations[](https://docs.nocodb.com/bases/actions-on-base/#relations "Direct link to Relations")
NocoDB provides a visual representation of the relations between tables within a base. To access the relations diagram, follow these steps:
1. Initiate the base context menu by clicking on the ellipses `...` located next to the base name within the left sidebar.
2. In the dropdown menu that appears, choose the `Relations` option.


### Related articles[](https://docs.nocodb.com/bases/actions-on-base/#related-articles "Direct link to Related articles")
- [Base overview](https://docs.nocodb.com/bases/base-overview)
- [Create an empty base](https://docs.nocodb.com/bases/create-base)
- [Import base from Airtable](https://docs.nocodb.com/bases/import-base-from-airtable)
- [Invite team members to work on a base](https://docs.nocodb.com/bases/base-collaboration)
- [Share base publicly](https://docs.nocodb.com/bases/share-base)
- [Rename base](https://docs.nocodb.com/bases/actions-on-base#rename-base)
- [Duplicate base](https://docs.nocodb.com/bases/actions-on-base#duplicate-base)
- [Bookmark base](https://docs.nocodb.com/bases/actions-on-base#star-base)
- [Delete base](https://docs.nocodb.com/bases/actions-on-base#delete-base)
---
# Webhook overview
You can employ webhooks to notify external systems whenever there are additions, updates, or removals of records within NocoDB. This feature allows you to receive instantaneous notifications for any changes made to your database. NocoDB also offers webhooks for bulk endpoints for creating, updating, or deleting multiple records simultaneously.
Note that, Webhooks currently are specific to associated table.
- [Create Webhook](https://docs.nocodb.com/developer-resources/webhook/create-webhook)
- [Disable Webhook](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#enabledisable-webhook)
- [Modify Webhook](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#edit-webhook)
- [Duplicate Webhook](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#duplicate-webhook)
- [Delete Webhook](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#delete-webhook)
# Create Webhook[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#create-webhook "Direct link to Create Webhook")
## Accessing webhook page[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#accessing-webhook-page "Direct link to Accessing webhook page")
1. Click on table for which webhook needs to be configured on the left sidebar
2. Open `Details` tab in topbar,
3. Click on `Webhooks` tab
4. Click `Add New Webhook`

## Configuring webhook[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#configuring-webhook "Direct link to Configuring webhook")
1. Name of the webhook
2. Select the event for which webhook needs to be triggered
|Trigger|Details|
|---|---|
|After Insert|After a single record is inserted|
|After Update|After a single record is updated|
|After Delete|After a single record is deleted|
|After Bulk Insert|After bulk records are inserted|
|After Bulk Update|After bulk records are updated|
|After Bulk Delete|After bulk records are deleted|
1. Method & URL: Configure the endpoint to which webhook needs to be triggered. Supported methods are GET, POST, DELETE, PUT, HEAD, PATCH
2. Headers & Parameters: Configure Request headers & parameters (optional)
3. Condition: Only records meeting the configured criteria will trigger webhook (optional)
4. Test webhook (with sample payload) to verify if parameter are configured appropriately (optional)
5. Save the webhook

## Webhook with conditions[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#webhook-with-conditions "Direct link to Webhook with conditions")
In case of webhook with conditions, only records meeting the configured criteria will trigger webhook. For example, trigger webhook only when `Status` is `Complete`. You can also configure multiple conditions using `AND` or `OR` operators. For example, trigger webhook only when `Status` is `Complete` and `Priority` is `High`.
The webhook will be triggered only when the configured condition wasn't met before the record was updated. For example, if you have configured webhook with condition `Status` `is` `Complete` and `Priority` `is` `High` and you update the record with `Status` `Complete` and `Priority` `Low` to `High`, webhook will be triggered. However, if you update any other fields of the record with `Status` `Complete` and `Priority` `High`, webhook won't be triggered.
In summary, the webhook will be triggered only when `Condition(old-record) = false` and `Condition(new-record) = true`.
## Webhook response sample[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#webhook-response-sample "Direct link to Webhook response sample")
- After Insert
```
{
"type": "records.after.insert",
"id": "9dac1c54-b3be-49a1-a676-af388145fa8c",
"data": {
"table_id": "md_xzru7dcqrecc60",
"table_name": "Film",
"view_id": "vw_736wrpoas7tr0c",
"view_name": "Film",
"records": [
{
"FilmId": 1011,
"Title": "FOO",
"Language": {
"LanguageId": 1,
"Name": "English"
},
}
]
}
}
```
- After Update
```
{
"type": "records.after.update",
"id": "6a6ebfe4-b0b5-434e-b5d6-5212adbf82fa",
"data": {
"table_id": "md_xzru7dcqrecc60",
"table_name": "Film",
"view_id": "vw_736wrpoas7tr0c",
"view_name": "Film",
"previous_records": [
{
"FilmId": 1,
"Title": "ACADEMY DINOSAUR",
"Description": "A Epic Drama of a Feminist in The Canadian Rockies",
"Actor List": [
{
"ActorId": 10,
"FirstName": "CHRISTIAN"
}
],
}
],
"records": [
{
"FilmId": 1,
"Title": "ACADEMY DINOSAUR (Edited)",
"Actor List": [
{
"ActorId": 10,
"FirstName": "CHRISTIAN"
}
],
}
]
}
}
```
- After Delete
```
{
"type": "records.after.delete",
"id": "e593079f-70e5-4965-8944-5ff7aeed005c",
"data": {
"table_id": "md_xzru7dcqrecc60",
"table_name": "Film",
"view_id": "vw_736wrpoas7tr0c",
"view_name": "Film",
"records": [
{
"FilmId": 1010,
"Title": "ALL-EDITED",
"Language": {
"LanguageId": 1,
"Name": "English"
},
}
]
}
}
```
- After Bulk Insert
```
{
"type": "records.after.bulkInsert",
"id": "f8397b06-a399-4a3a-b6b0-6d1c0c2f7578",
"data": {
"table_id": "md_xzru7dcqrecc60",
"table_name": "Film",
"view_id": "vw_3fq2e9q8drkblw",
"view_name": "GridView",
"records_inserted": 2
}
}
```
- After Bulk Update
```
{
"type": "records.after.bulkUpdate",
"id": "e983cea5-8e38-438e-96a0-048751f6830b",
"data": {
"table_id": "md_xzru7dcqrecc60",
"table_name": "Film",
"view_id": "vw_3fq2e9q8drkblw",
"view_name": "Sheet-1",
"previous_records": [
[
{
"FilmId": 1005,
"Title": "Q",
"Language": {
"LanguageId": 1,
"Name": "English"
},
},
{
"FilmId": 1004,
"Title": "P",
"Language": {
"LanguageId": 1,
"Name": "English"
}
}
]
],
"records": [
[
{
"FilmId": 1005,
"Title": "Q-EDITED",
"Language": {
"LanguageId": 1,
"Name": "English"
}
},
{
"FilmId": 1004,
"Title": "P-EDITED",
"Language": {
"LanguageId": 1,
"Name": "English"
},
}
]
]
}
}
```
- After Bulk Delete
```
{
"type": "records.after.bulkDelete",
"id": "e7f1f4e5-7052-4ca2-9355-241ceb836f43",
"data": {
"table_id": "md_xzru7dcqrecc60",
"table_name": "Film",
"view_id": "vw_3fq2e9q8drkblw",
"view_name": "Sheet-1",
"records": [
[
{
"FilmId": 1022,
"Title": "x",
"Language": {
"LanguageId": 1,
"Name": "English"
},
},
{
"FilmId": 1023,
"Title": "x",
"Language": {
"LanguageId": 1,
"Name": "English"
},
}
]
]
}
}
```
## Webhook with custom payload ☁[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#webhook-with-custom-payload- "Direct link to Webhook with custom payload ☁")
In the enterprise edition, you can set up a personalized payload for your webhook. Just head to the `Body` tab to make the necessary configurations. Users can utilize [handlebar syntax](https://handlebarsjs.com/guide/#simple-expressions), which allows them to access and manipulate the data easily.
Use `{{ json event }}` to access the event data. Sample response is as follows
```
{
"type": "records.after.insert",
"id": "0698517a-d83a-4e72-bf7a-75f46b704ad1",
"data": {
"table_id": "m969t01blwprpef",
"table_name": "Table-2",
"view_id": "vwib3bvfxdqgymun",
"view_name": "Table-2",
"rows": [
{
"Id": 1,
"Tags": "Sample Text",
"CreatedAt": "2024-04-11T10:40:20.998Z",
"UpdatedAt": "2024-04-11T10:40:20.998Z"
}
]
}
}
```
info
**Note:** The custom payload feature is only available in the enterprise edition.
#### Discord Webhook[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#discord-webhook "Direct link to Discord Webhook")
Discord webhook can be configured to send messages to a Discord channel. Discord request body should contain content, embeds or attachments, otherwise request will fail. Below is an example of Discord webhook payload. More details can be found [here](https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html)
```
{
"content": "Hello, this is a webhook message",
"embeds": [
{
"title": "Webhook",
"description": "This is a webhook message",
"color": 16711680
}
]
}
```
To send complete event data to Discord, use below payload
```
{
"content" : {{ json ( json event ) }}
}
```
One can also customize the payload as per the requirement. For example, to send only the `Title` field to Discord, use below payload. Note that, the value of `content` is what that will get displayed in the Discord channel.
```
{
"content": "{{ event.data.rows.[0].Title }}"
}
```
## Environment Variables[](https://docs.nocodb.com/developer-resources/webhook/create-webhook/#environment-variables "Direct link to Environment Variables")
In self-hosted version, you can configure the following environment variables to customize the webhook behavior.
- NC_ALLOW_LOCAL_HOOKS: Allow localhost based links to be triggered. Default: false
Find more about environment variables [here](https://docs.nocodb.com/getting-started/self-hosted/environment-variables)
# Actions on webhook
### Enable/disable Webhook[](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#enabledisable-webhook "Direct link to Enable/disable Webhook")
To disable a Webhook +
- Open `Webhook` tab to find list of webhooks created
- Toggle `Activate` button to enable/disable

### Edit Webhook[](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#edit-webhook "Direct link to Edit Webhook")
To edit a Webhook
- Open `Webhook` tab to find list of webhooks created
- Click on webhook to be edited
- This will open up the webhook configuration page, which is similar to the page used for [creating webhook](https://docs.nocodb.com/automation/webhook/create-webhook). Reconfigure the webhook as required
- Click on `Save` button to save the changes
### Duplicate Webhook[](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#duplicate-webhook "Direct link to Duplicate Webhook")
To duplicate a Webhook
- Open `Webhook` tab to find list of webhooks created
- Click on `...` actions button associated with the webhook to be duplicate
- Select `Duplicate`

A copy of the webhook will be created (disabled by default) with a suffix `- Copy`
### Delete Webhook[](https://docs.nocodb.com/developer-resources/webhook/actions-on-webhook#delete-webhook "Direct link to Delete Webhook")
To delete a Webhook
- Open the `Webhook` tab to find the list of webhooks created
- Click on the `...` actions button associated with the webhook to be deleted
- Select `Delete`

---
# Architecture overview
By default, if `NC_DB` is not specified, then SQLite will be used to store your metadata. We suggest users to separate the metadata and user data in different databases.

| Project Type | Metadata stored in | Data stored in |
| -------------------------------------- | ------------------ | ----------------- |
| Create new base | NC_DB | NC_DB |
| Create new base with External Database | NC_DB | External Database |
| Create new base from Excel | NC_DB | NC_DB |
# Repository structure
We use `Lerna` to manage multi-packages. We have the following [packages](https://github.com/nocodb/nocodb/tree/master/packages).
- `packages/nc-cli` : A CLI to create NocoDB app.
- `packages/nocodb-sdk`: API client sdk of nocodb.
- `packages/nc-gui`: NocoDB Frontend.
- `packages/nc-lib-gui`: The build version of `nc-gui` which will be used in `packages/nocodb`.
- `packages/noco-blog`: NocoDB Blog which will be auto-released to [nocodb/noco-blog](https://github.com/nocodb/noco-blog).
- `packages/noco-docs`: NocoDB Documentation which will be auto-released to [nocodb/noco-docs](https://github.com/nocodb/noco-docs).
- `packages/nocodb`: NocoDB Backend, hosted in [NPM](https://www.npmjs.com/package/nocodb).
# Development Setup
## Clone the repo[](https://docs.nocodb.com/engineering/development-setup#clone-the-repo "Direct link to Clone the repo")
```
git clone https://github.com/nocodb/nocodb# change directory to the project rootcd nocodb
```
## Install dependencies[](https://docs.nocodb.com/engineering/development-setup#install-dependencies "Direct link to Install dependencies")
```
# run from the project root# this command will install the dependencies including sdk buildpnpm bootstrap
```
## Start Frontend[](https://docs.nocodb.com/engineering/development-setup#start-frontend "Direct link to Start Frontend")
```
# run from the project rootpnpm start:frontend# runs on port 3000
```
## Start Backend[](https://docs.nocodb.com/engineering/development-setup#start-backend "Direct link to Start Backend")
```
# run from the project rootpnpm start:backend# runs on port 8080
```
Any changes made to frontend and backend will be automatically reflected in the browser.
## Enabling CI-CD for Draft PR[](https://docs.nocodb.com/engineering/development-setup#enabling-ci-cd-for-draft-pr "Direct link to Enabling CI-CD for Draft PR")
CI-CD will be triggered on moving a PR from draft state to `Ready for review` state & on pushing changes to `Develop`. To verify CI-CD before requesting for review, add label `trigger-CI` on Draft PR.
## Accessing CI-CD Failure Screenshots[](https://docs.nocodb.com/engineering/development-setup#accessing-ci-cd-failure-screenshots "Direct link to Accessing CI-CD Failure Screenshots")
For Playwright tests, screenshots are captured on the tests. These will provide vital clues for debugging possible issues observed in CI-CD. To access screenshots, Open link associated with CI-CD run & click on `Artifacts`

# Writing unit tests
## Unit Tests[](https://docs.nocodb.com/engineering/unit-testing#unit-tests "Direct link to Unit Tests")
- All individual unit tests are independent of each other. We don't use any shared state between tests.
- Test environment includes `sakila` sample database and any change to it by a test is reverted before running other tests.
- While running unit tests, it tries to connect to mysql server running on `localhost:3306` with username `root` and password `password` (which can be configured) and if not found, it will use `sqlite` as a fallback, hence no requirement of any sql server to run tests.
### Pre-requisites[](https://docs.nocodb.com/engineering/unit-testing#pre-requisites "Direct link to Pre-requisites")
- MySQL is preferred - however tests can fallback on SQLite too
### Setup[](https://docs.nocodb.com/engineering/unit-testing#setup "Direct link to Setup")
```
pnpm --filter=-nocodb install
# add a .env file
cp tests/unit/.env.sample tests/unit/.env
# open .env file
open tests/unit/.env
```
Configure the following variables
> DB_HOST : host DB_PORT : port DB_USER : username DB_PASSWORD : password
### Run Tests[](https://docs.nocodb.com/engineering/unit-testing#run-tests "Direct link to Run Tests")
```
pnpm run test:unit
```
### Folder Structure[](https://docs.nocodb.com/engineering/unit-testing#folder-structure "Direct link to Folder Structure")
The root folder for unit tests is `packages/nocodb/tests/unit`
- `rest` folder contains all the test suites for rest apis.
- `model` folder contains all the test suites for models.
- `factory` folder contains all the helper functions to create test data.
- `init` folder contains helper functions to configure test environment.
- `index.test.ts` is the root test suite file which imports all the test suites.
- `TestDbMngr.ts` is a helper class to manage test databases (i.e. creating, dropping, etc.).
### Factory Pattern[](https://docs.nocodb.com/engineering/unit-testing#factory-pattern "Direct link to Factory Pattern")
- Use factories for create/update/delete data. No data should be directly create/updated/deleted in the test.
- While writing a factory make sure that it can be used with as less parameters as possible and use default values for other parameters.
- Use named parameters for factories.
```
createUser({ email, password})
```
- Use one file per factory.
### Walk through of writing a Unit Test[](https://docs.nocodb.com/engineering/unit-testing#walk-through-of-writing-a-unit-test "Direct link to Walk through of writing a Unit Test")
We will create an `Table` test suite as an example.
#### Configure test[](https://docs.nocodb.com/engineering/unit-testing#configure-test "Direct link to Configure test")
We will configure `beforeEach` which is called before each test is executed. We will use `init` function from `nocodb/packages/nocodb/tests/unit/init/index.ts`, which is a helper function which configures the test environment(i.e resetting state, etc.).
`init` does the following things -
- It initializes a `Noco` instance(reused in all tests).
- Restores `meta` and `sakila` database to its initial state.
- Creates the root user.
- Returns `context` which has `auth token` for the created user, node server instance(`app`), and `dbConfig`.
We will use `createProject` and `createProject` factories to create a project and a table.
```
let context;
beforeEach(async function () {
context = await init();
project = await createProject(context);
table = await createTable(context, project);
});
```
#### Test case[](https://docs.nocodb.com/engineering/unit-testing#test-case "Direct link to Test case")
We will use `it` function to create a test case. We will use `supertest` to make a request to the server. We use `expect`(`chai`) to assert the response.
```
it('Get table list', async function () {
const response = await request(context.app)
.get(`/api/v1/db/meta/projects/${project.id}/tables`)
.set('xc-auth', context.token)
.send({})
.expect(200);
expect(response.body.list).to.be.an('array').not.empty;
});
```
info
We can also run individual test by using `.only` in `describe` or `it` function and the running the test command.
```
it.only('Get table list', async () => {
```
#### Integrating the New Test Suite[](https://docs.nocodb.com/engineering/unit-testing#integrating-the-new-test-suite "Direct link to Integrating the New Test Suite")
We create a new file `table.test.ts` in `packages/nocodb/tests/unit/rest/tests` directory.
```
import 'mocha';
import request from 'supertest';
import init from '../../init';
import { createTable, getAllTables } from '../../factory/table';
import { createProject } from '../../factory/project';
import { defaultColumns } from '../../factory/column';
import Model from '../../../../src/lib/models/Model';
import { expect } from 'chai';
function tableTest() {
let context;
let project;
let table;
beforeEach(async function () {
context = await init();
project = await createProject(context);
table = await createTable(context, project);
});
it('Get table list', async function () {
const response = await request(context.app)
.get(`/api/v1/db/meta/projects/${project.id}/tables`)
.set('xc-auth', context.token)
.send({})
.expect(200);
expect(response.body.list).to.be.an('array').not.empty;
});
}
export default function () {
describe('Table', tableTests);
}
```
We can then import the `Table` test suite to `Rest` test suite in `packages/nocodb/tests/unit/rest/index.test.ts` file(`Rest` test suite is imported in the root test suite file which is `packages/nocodb/tests/unit/index.test.ts`).
### Seeding Sample DB (Sakila)[](https://docs.nocodb.com/engineering/unit-testing#seeding-sample-db-sakila "Direct link to Seeding Sample DB (Sakila)")
```
function tableTest() {
let context;
let sakilaProject: Project;
let customerTable: Model;