-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathv2.apib
1524 lines (1109 loc) · 68 KB
/
v2.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
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
FORMAT: 1A
HOST: https://inbdpa.api.hscc.bdpa.org/v2
# InBDPA API (VERSION 2)
> We're looking for feedback! If you have any opinions or ideas, contact us on Slack.
Based on [simple REST principles](https://restfulapi.net), the InBDPA API returns JSON data responses to requests. This is the API used by teams and their apps for the BDPA National High School Computer Competition. It contains all of the data teams' apps must interact with. The API is live and will ideally remain online indefinitely.
The base address of the InBDPA API is https://inbdpa.api.hscc.bdpa.org/V where `V` is the version of the API you want to use (either `V = v1` or `V = v2`). Each version of the API provides a set of endpoints with their own unique path and requirements.
[The source code behind the API is available on GitHub](https://github.com/nhscc/inbdpa.api.hscc.bdpa.org). If you have any trouble, [open an issue there](https://github.com/nhscc/inbdpa.api.hscc.bdpa.org/issues/new) or contact us on Slack.
> Notice: due to financial constraints, the oldest documents in the system will be dropped from the API to make room for the new. That is: `<item>_id`s are not guaranteed to exist forever!
## Migration Guide
Changes between version 1 and version 2:
- New [Articles documentation](#/reference/0/article-endpoints) with new article-related CRUD endpoints
- The number of articles in the system is now reported by the [/info (GET)](#/reference/0/info-endpoints/info-get) endpoint and must be included in relevant output.
- Improved session tracking API
- [Sessions](#/data-structures/0/session) now track the user and the view
- New [/sessions (GET)](#/reference/0/session-endpoints/sessions-get) and [/sessions/:session_id (GET)](#/reference/0/session-endpoints/sessions-session-id-get) endpoints.
- New session endpoints specific to users ([/users/:user_id/sessions (GET)](#/reference/0/user-endpoints/users-user-id-sessions-get)), opportunities ([/opportunities/:opportunity_id/sessions (GET)](#/reference/0/opportunity-endpoints/opportunities-opportunity-id-sessions-get)), and articles ([/articles/:article_id/sessions (GET)](#/reference/0/article-endpoints/articles-article-id-sessions-get)).
- Deprecation of the [/sessions/count-for/user/:user_id (GET)](https://hsccrkby0uo4.docs.apiary.io/#/reference/0/session-endpoints/sessions-count-for-user-user-id-get) and [/sessions/count-for/opportunity/:opportunity_id (GET)](https://hsccrkby0uo4.docs.apiary.io/#/reference/0/session-endpoints/sessions-count-for-opportunity-opportunity-id-get) endpoints.
- Active session counts are now included in the [User](#/data-structures/0/user) and [Opportunity](#/data-structures/0/opportunity) (and [Article](#/data-structures/0/article)) response objects under the `sessions` property.
- [/sessions (POST)](#/reference/0/session-endpoints/sessions-post) now allows a [nullable](https://apiblueprint.org/documentation/mson/specification.html#353-type-attribute) `user_id` parameter.
- Example: if `user-A` loads `user-E`'s profile via the [Profile view](https://github.com/nhscc/problem-statements/blob/main/2023/inbdpa/inbdpa-part-1.md#requirement-3), then your solution must create a new session that includes `user-A`'s `user_id`, the "profile" view type, and `user-E`'s ID as the ID of the viewed item.
- [/users (POST)](#/reference/0/user-endpoints/users-post) now requires a `fullName` property. Similarly, users' full names are now included in the [User](#/data-structures/0/user) response objects under the `fullName` property.
Any API calls using deprecated endpoints need to be updated to use the new endpoint.
> Be advised: **the V1 API will be disabled several hours into the competition**. For posterity, V1 endpoints will be re-enabled after ~72 hours.
## Requesting a Key
To access the majority of this API's endpoints requires a key. If your team needs a key, or to replace a lost or stolen key, either use our Slack bot (BDPABot) to manage your team's keys or contact us on Slack.
When you get your key, include it as your request's [Authorization header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization) and you will be immediately authenticated into the system. For example: `Authorization: bearer your-special-api-key-here`.
## Rules of API Access
1. Do not bombard the API with requests or you risk permanent IP/subnet ban. **Limit your apps to no more than 10 requests per second per API key**. If your app ends up sending too many requests over some time period, you'll get a `HTTP 429` response along with a monotonically increasing soft ban (starting at 15 minutes). Similarly, the size of requests is strictly limited, so you must limit the amount of data you're sending. When you send a request that is too large (>100KB), it will fail with a `HTTP 413` response.
2. **Do not reveal your API key to anyone** not on your own team. It is how the API identifies your team. Do not upload it to GitHub or leave it lying around in your source code. Save it to a file and `.gitignore` it or save it to an environment variable.
3. Since the API is live, you might be able to see or interact with content posted by other teams. If this is the case, please do not post anything inappropriate.
4. If you have a relevant feature request or you encounter any vulnerabilities, errors, or other issues, don't hesitate to contact NHSCC staff via Slack or [open an issue on GitHub](https://github.com/nhscc/inbdpa.api.hscc.bdpa.org). For significant enough finds, bonus points may be awarded. On the other hand, abusing any vulnerability or bug may result in disqualification.
5. **The API was built to randomly return errors every so often**. That means your app must be prepared to deal with `HTTP 555` and other bad responses. However, if you're consistently getting `HTTP 5xx` errors back to back, then something is wrong. Please report this if it happens.
6. All responses are raw JSON. All request payloads must be sent as raw JSON. `JSON.stringify()` and `JSON.parse()` or whatever language equivalent is available to you is your friend!
## Request Methods
This API is based on [simple REST principles](https://restfulapi.net). Resources are accessed via standard HTTPS requests in UTF-8 format to an API endpoint. This API understands the following HTTP request methods:
| METHOD | MEANING |
|----- |----- |
| GET | Return data about something |
| POST | Create something new |
| PATCH | Modify something |
| PATCH | Partially modify something |
| DELETE | Delete something |
## Rate Limits
As said earlier, do not bombard the API with requests. If you do, the API will soft ban you for fifteen minutes the first time before accepting requests from your API key or IP address again. Each following time this happens within a certain period, your ban time will quadruple.
So **limit your apps to no more than 10 requests per second per API key**. You know you've been soft banned if you receive an `HTTP 429` response. Check the JSON response for the `retryAfter` key, which represents for how long your API key and/or IP are banned from making further requests (in milliseconds).
If this is the first time you've been banned, you can use the Slack bot to unban yourself immediately. If the Slack bot is not available or this is not the first time you've been banned, contact us on Slack.
## Pagination
Endpoints that might return a lot of items (users, documents, etc) are paginated via [range queries](https://en.wikipedia.org/wiki/Range_query_(database)). Such endpoints optionally accept an `after` parameter, which is an `<item>_id` or other identifier that determines which API item is returned first. That is: the first item will be the first `<item>_id` that comes *after* the `after` `<item>_id`. Omitting the `after` parameter returns the first 100 items in the system.
For example, given the following dataset and an API with a default result size (or "page" size) of 3:
```JavaScript
[
{ item_id: 0xabc123, name: 'Item 1 name' },
{ item_id: 0xabc124, name: 'Item 2 name' },
{ item_id: 0xabc125, name: 'Item 3 name' },
{ item_id: 0xabc126, name: 'Item 4 name' },
{ item_id: 0xabc127, name: 'Item 5 name' },
]
```
Suppose we issued the following requests to an API:
`/api?after=0xabc123`: responds with an array of 3 items: *0xabc124* through *0xabc126*
`/api?after=0xabcXYZ`: responds with an array of 0 items since `item_id` *0xabcXYZ* doesn't exist
`/api?after=0xabc124`: responds with an array of 3 items: *0xabc125* through *0xabc127*
`/api?after=0xabc127`: responds with an array of 0 items since there is nothing after *0xabc127*
`/api?after=0xabc125`: responds with an array of 2 items: *0xabc126* and *0xabc127*
## Status Codes
This API will issue responses with one of the following status codes:
| STATUS | MEANING |
|----- |----- |
| 200 | Your request completed successfully. |
| 400 | Your request was malformed or otherwise bad. Check the requirements. |
| 401 | Session is not authenticated. Put your API key in the header! |
| 403 | Session is not authorized. You tried to do something you can't do. |
| 404 | The resource (or endpoint) was not found. Check your syntax. |
| 405 | Bad method. The endpoint does not support your request's method. |
| 413 | Your request was too large and was dropped. Max body size is 100KB. |
| 415 | Your request was made using the wrong Content-Type header value. |
| 429 | You've been rate limited. Try your request again after a few minutes. |
| 4xx | Your request was malformed in some way. |
| 5xx | Something happened on the server that is outside your control. |
## Response Schema
All responses issued by the API will follow one of the two following schemas.
### Success Schema
When a request you've issued succeeds, the response will look like the following:
```json
{
"success": "true",
// any other data you requested
}
```
Note that all time data is represented as the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC, or the same thing that is returned by JavaScript's `Date.now()` method.
### Error Schema
When a request you've issued fails, along with the non-200 status code, the response will look like the following:
```json
{
"error": "an error message describing what went wrong",
// any other relevant data (like retryAfter)
}
```
## CORS Support
The API has full support for Cross Origin Resource Sharing (CORS) for AJAX requests.
## Tips for Debugging
- Are you using the right method?
- Use this documentation (click "see example," then click "Try console") or use [Postman](https://www.postman.com/downloads) to play with the API.
- Expect a raw JSON response body that you must parse manually, not raw text or something else.
- Are you sending properly formatted JSON payloads in your request body when necessary?
- Try outputting to stdout, use `console.log`, or output to some log file when API requests are made and responses received.
- All time data is represented as [the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now).
- Are you sending the correct headers? You need to specify the `Authorization: bearer your-special-api-key-here` header for all requests and the `'content-type': 'application/json'` header when making POST and PATCH requests.
- Are you [encoding your URI components](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) properly, especially when you're trying to send the API [JSON objects](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON) via [GET request](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods)?
## Globally Unique IDs
To retrieve data about one or more API items, you must know that item's `<item>_id`. These and other IDs are globally unique within the API. That is: no two items will ever have the same ID in any instance. Use this fact to your advantage.
## Article Endpoints [/articles]
These endpoints deal with [CRUD operations](https://nordicapis.com/crud-vs-rest-whats-the-difference) on articles.
- [/articles (GET)](#/reference/0/article-endpoints/articles-get)
- [/articles (POST)](#/reference/0/article-endpoints/articles-post)
- [/articles/:article_id (GET)](#/reference/0/article-endpoints/articles-article-id-get)
- [/articles/:article_id (PATCH)](#/reference/0/article-endpoints/articles-article-id-patch)
- [/articles/:article_id (DELETE)](#/reference/0/article-endpoints/articles-article-id-delete)
- [/articles/:article_id/sessions (GET)](#/reference/0/article-endpoints/articles-article-id-sessions-get)
### /articles (GET) [GET /articles{?after,updatedAfter}]
Retrieves all articles in the system in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order.
Retrievals are limited to at most 100 results per query. Supports [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) using `after`.
+ Parameters
+ `after` (optional, article_id) - <span style="color: gray">[optional]</span> Return only those results that occur *after* `after` in the result list.
+ `updatedAfter` (optional, number) - <span style="color: gray">[optional]</span> Return only those users with [`updatedAt`](#/data-structures/0/article) greater than `updatedAfter`.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ articles (array[Article]) - An array of article objects. Empty if there are no articles left to show.
+ Body
{
"success": true,
"articles": [
{
"article_id": "5eee34b3ca37750008547373",
"title": "Epidemic Of Unpaid Internships Requiring Masters Degrees",
"views": 1250,
"sessions": 210,
"contents": "...",
"keywords": ["epidemic", "unpaid", "internship", "degree"],
"createdAt": 1579345909352,
"updatedAt": 1579345909687,
"creator_id": "5eee34b3ca37750008547375"
},
{
"article_id": "5eee34b3ca37750008547374",
"title": "\"It's Totally Ethical!\" Says CEO On Yacht In Response To Complaints Over 50-Year Experience Requirement For Unpaid Internships",
"views": 987,
"sessions": 0,
"contents": "...",
"keywords": ["it's", "a", "metaphor", "for", "capitalism"],
"createdAt": 1579347789639,
"updatedAt": 1579347789639,
"creator_id": "5eee34b3ca37750008547376"
}
]
}
### /articles (POST) [POST /articles]
Creates a new article.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Attributes
+ title: `"My Little Article"` (string) - The title of the article.
+ contents (string) - The Markdown contents describing the article.
+ creator_id: `"5eee34b3ca37750008547375"` (string) - The ID of the user that created the article.
+ keywords (array[string]) - An array of keyword strings associated with the article and its contents.
+ Body
{
"title": "Unpaid Internship Requiring Masters Degree",
"contents": "...",
"creator_id": "5eee34b3ca37750008547375"
"keywords": ["epidemic", "unpaid", "internship", "degree"]
}
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ article (Article) - The newly created article object.
+ Body
{
"success": true,
"article": {
"article_id": "5eee34b3ca37750008547374",
"title": "Epidemic Of Unpaid Internships Requiring Masters Degrees",
"views": 125,
"sessions": 21,
"contents": "...",
"keywords": ["epidemic", "unpaid", "internship", "degree"],
"createdAt": 1579345909352,
"updatedAt": 1579345909687,
"creator_id": "5eee34b3ca37750008547375"
}
}
### /articles/:article_id (GET) [GET /articles/{article_id}]
Retrieve an article by its `article_id`.
+ Parameters
+ `article_id`: `5eee34b3ca37750008547375` (article_id) - <span style="color: darkred">[required]</span> ID of the article.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ article (Article) - The requested article object.
+ Body
{
"success": true,
"article": {
"article_id": "5eee34b3ca37750008547374",
"title": "Epidemic Of Unpaid Internships Requiring Masters Degrees",
"views": 125,
"sessions": 21,
"contents": "...",
"keywords": ["epidemic", "unpaid", "internship", "degree"],
"createdAt": 1579345909352,
"updatedAt": 1579345909687,
"creator_id": "5eee34b3ca37750008547375"
}
}
### /articles/:article_id (PATCH) [PATCH /articles/{article_id}]
Update an article (`article_id`) in the system. The article's `updatedAt` timestamp is also updated.
+ Parameters
+ `article_id`: `5eee34b3ca37750008547375` (article_id) - <span style="color: darkred">[required]</span> ID of the article.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Attributes (object)
+ title: `"My Little Article"` (optional, string) - The title of the article.
+ contents (optional, string) - The Markdown contents describing the article.
+ views: `"increment"` (optional, string) - If the views should be incremented. If this property is present, it must have the value `"increment"`.
+ Body
{
"title": `"My BIG Article!"`,
"views": "increment"
}
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ Body
{
"success": true
}
### /articles/:article_id (DELETE) [DELETE /articles/{article_id}]
Completely and permanently remove an article from the system.
+ Parameters
+ `article_id`: `5eee34b3ca37750008547375` (article_id) - <span style="color: darkred">[required]</span> ID of the article.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ Body
{
"success": true
}
### /articles/:article_id/sessions (GET) [GET /articles/{article_id}/sessions{?after}]
Retrieves all sessions in the system associated with a specific article (`article_id`) and in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order.
Retrievals are limited to at most 100 results per query. Supports [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) using `after`.
+ Parameters
+ `article_id`: `5eee34b3ca37750008547375` (article_id) - <span style="color: darkred">[required]</span> ID of the article.
+ `after` (optional, session_id) - <span style="color: gray">[optional]</span> Return only those results that occur *after* `after` in the result list.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ sessions (array[Session]) - An array of session objects. Empty if there are no sessions left to show.
+ Body
{
"success": true,
"sessions": [
{
"session_id": "5eee34b3ca37750008547374",
"user_id": null,
"view": "article",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900770,
"updatedAt": 1579345900770
},
{
"session_id": "5eee34b3ca37750008547373",
"user_id": "5ec8adf06e38e58770ff2136",
"view": "article",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900655,
"updatedAt": 1579345998766
},
{
"session_id": "5ec8adff2e5877f0813706e3",
"user_id": "5ec8adf06e38e58770ff2137",
"view": "article",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900650,
"updatedAt": 1579345900650
}
]
}
## Info Endpoints [/info]
These endpoints allow retrieval of statistics describing the entire system.
- [/info (GET)](#/reference/0/info-endpoints/info-get)
### /info (GET) [GET /info]
Get metadata about the entire system.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ info (Info) - Metadata about the entire system.
+ Body
{
"success": true,
"info": {
"articles": 60608,
"opportunities": 17,
"sessions": 5,
"users": 3,
"views": 91356
}
}
## Opportunity Endpoints [/opportunities]
These endpoints deal with [CRUD operations](https://nordicapis.com/crud-vs-rest-whats-the-difference) on opportunities.
- [/opportunities (GET)](#/reference/0/opportunity-endpoints/opportunities-get)
- [/opportunities (POST)](#/reference/0/opportunity-endpoints/opportunities-post)
- [/opportunities/:opportunity_id (GET)](#/reference/0/opportunity-endpoints/opportunities-opportunity-id-get)
- [/opportunities/:opportunity_id (PATCH)](#/reference/0/opportunity-endpoints/opportunities-opportunity-id-patch)
- [/opportunities/:opportunity_id (DELETE)](#/reference/0/opportunity-endpoints/opportunities-opportunity-id-delete)
- [/opportunities/:opportunity_id/sessions (GET)](#/reference/0/opportunity-endpoints/opportunities-opportunity-id-sessions-get)
### /opportunities (GET) [GET /opportunities{?after,updatedAfter}]
Retrieves all opportunities in the system in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order.
Retrievals are limited to at most 100 results per query. Supports [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) using `after`.
+ Parameters
+ `after` (optional, opportunity_id) - <span style="color: gray">[optional]</span> Return only those results that occur *after* `after` in the result list.
+ `updatedAfter` (optional, number) - <span style="color: gray">[optional]</span> Return only those users with [`updatedAt`](#/data-structures/0/opportunity) greater than `updatedAfter`.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ opportunities (array[Opportunity]) - An array of opportunity objects. Empty if there are no opportunities left to show.
+ Body
{
"success": true,
"opportunities": [
{
"opportunity_id": "5eee34b3ca37750008547374",
"title": "Unpaid Internship Requiring Masters Degree",
"views": 521,
"sessions": 13,
"contents": "...",
"createdAt": 1579345900650,
"updatedAt": 1579345900650,
"creator_id": "5eee34b3ca37750008547376"
},
{
"opportunity_id": "5eee34b3ca37750008547375",
"title": "Unpaid Internship Requiring 50 Years Experience",
"views": 44,
"sessions": 6,
"contents": "...",
"createdAt": 1579345900650,
"updatedAt": 1579345900650,
"creator_id": "5eee34b3ca37750008547376"
}
]
}
### /opportunities (POST) [POST /opportunities]
Creates a new opportunity.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Attributes
+ title: `"My Little Opportunity"` (string) - The title of the opportunity.
+ contents (string) - The Markdown contents describing the opportunity.
+ creator_id: `"5eee34b3ca37750008547375"` (string) - The ID of the user that created the opportunity.
+ Body
{
"title": "Unpaid Internship Requiring Masters Degree",
"contents": "...",
"creator_id": "5eee34b3ca37750008547375"
}
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ opportunity (Opportunity) - The newly created opportunity object.
+ Body
{
"success": true,
"opportunity": {
"opportunity_id": "5eee34b3ca37750008547374",
"title": "Unpaid Internship Requiring Masters Degree",
"views": 0,
"sessions": 0,
"contents": "...",
"createdAt": 1579345900650,
"updatedAt": 1579345900650,
"creator_id": "5eee34b3ca37750008547375"
}
}
### /opportunities/:opportunity_id (GET) [GET /opportunities/{opportunity_id}]
Retrieve an opportunity by its `opportunity_id`.
+ Parameters
+ `opportunity_id`: `5eee34b3ca37750008547375` (opportunity_id) - <span style="color: darkred">[required]</span> ID of the opportunity.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ opportunity (Opportunity) - The requested opportunity object.
+ Body
{
"success": true,
"opportunity": {
"opportunity_id": "5eee34b3ca37750008547374",
"title": "Unpaid Internship Requiring Masters Degree",
"views": 521,
"sessions": 12,
"contents": "...",
"createdAt": 1579345900650,
"updatedAt": 1579345900650,
"creator_id": "5eee34b3ca37750008547375"
}
}
### /opportunities/:opportunity_id (PATCH) [PATCH /opportunities/{opportunity_id}]
Update an opportunity (`opportunity_id`) in the system. The opportunity's `updatedAt` timestamp is also updated.
+ Parameters
+ `opportunity_id`: `5eee34b3ca37750008547375` (opportunity_id) - <span style="color: darkred">[required]</span> ID of the opportunity.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Attributes (object)
+ title: `"My Little Opportunity"` (optional, string) - The title of the opportunity.
+ contents (optional, string) - The Markdown contents describing the opportunity.
+ views: `"increment"` (optional, string) - If the views should be incremented. If this property is present, it must have the value `"increment"`.
+ Body
{
"title": `"My BIG Opportunity!"`
}
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ Body
{
"success": true
}
### /opportunities/:opportunity_id (DELETE) [DELETE /opportunities/{opportunity_id}]
Completely and permanently remove an opportunity from the system.
+ Parameters
+ `opportunity_id`: `5eee34b3ca37750008547375` (opportunity_id) - <span style="color: darkred">[required]</span> ID of the opportunity.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ Body
{
"success": true
}
### /opportunities/:opportunity_id/sessions (GET) [GET /opportunities/{opportunity_id}/sessions{?after}]
Retrieves all sessions in the system associated with a specific opportunity (`opportunity_id`) and in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order.
Retrievals are limited to at most 100 results per query. Supports [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) using `after`.
+ Parameters
+ `opportunity_id`: `5eee34b3ca37750008547375` (opportunity_id) - <span style="color: darkred">[required]</span> ID of the opportunity.
+ `after` (optional, session_id) - <span style="color: gray">[optional]</span> Return only those results that occur *after* `after` in the result list.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ sessions (array[Session]) - An array of session objects. Empty if there are no sessions left to show.
+ Body
{
"success": true,
"sessions": [
{
"session_id": "5eee34b3ca37750008547374",
"user_id": null,
"view": "opportunity",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900770,
"updatedAt": 1579345900770
},
{
"session_id": "5eee34b3ca37750008547373",
"user_id": "5ec8adf06e38e58770ff2136",
"view": "opportunity",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900655,
"updatedAt": 1579345998766
},
{
"session_id": "5ec8adff2e5877f0813706e3",
"user_id": "5ec8adf06e38e58770ff2137",
"view": "opportunity",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900650,
"updatedAt": 1579345900650
}
]
}
## Session Endpoints [/sessions]
These endpoints deal with [CRUD operations](https://nordicapis.com/crud-vs-rest-whats-the-difference) on active viewer sessions.
- [/sessions (GET)](#/reference/0/session-endpoints/sessions-get)
- [/sessions (POST)](#/reference/0/session-endpoints/sessions-post)
- [/sessions/:session_id (GET)](#/reference/0/session-endpoints/sessions-session-id-get)
- [/sessions/:session_id (PATCH)](#/reference/0/session-endpoints/sessions-session-id-patch)
- [/sessions/:session_id (DELETE)](#/reference/0/session-endpoints/sessions-session-id-delete)
### /sessions (GET) [GET /sessions{?after,updatedAfter}]
Retrieves all sessions in the system in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order.
Retrievals are limited to at most 100 results per query. Supports [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) using `after`.
+ Parameters
+ `after` (optional, session_id) - <span style="color: gray">[optional]</span> Return only those results that occur *after* `after` in the result list.
+ `updatedAfter` (optional, number) - <span style="color: gray">[optional]</span> Return only those results with [`updatedAt`](#/data-structures/0/user) greater than `updatedAfter`.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ sessions (array[Session]) - An array of session objects. Empty if there are no sessions left to show.
+ Body
{
"success": true,
"sessions": [
{
"session_id": "5eee34b3ca37750008547374",
"user_id": null,
"view": "auth",
"viewed_id": null,
"createdAt": 1579345900770,
"updatedAt": 1579345900770
},
{
"session_id": "5eee34b3ca37750008547373",
"user_id": "5ec8adf06e38e58770ff2136",
"view": "profile",
"viewed_id": "5ec8adf06e38e58770ff2137",
"createdAt": 1579345900655,
"updatedAt": 1579345998766
},
{
"session_id": "5ec8adff2e5877f0813706e3",
"user_id": "5ec8adf06e38e58770ff2137",
"view": "article",
"viewed_id": "5ec8adf06e38137ff2e58770",
"createdAt": 1579345900650,
"updatedAt": 1579345900650
}
]
}
### /sessions (POST) [POST /sessions]
Make the API aware of an active session, which represents one client (`user_id`) interacting with one view (`view` + `viewed_id`). Active sessions expire 30 seconds after their creation unless they are [renewed](#/reference/0/session-endpoints/sessions-session-id-patch), which will reset the 30-second timer.
Example usage: if `user-A` clicks a link to `user-B`'s profile, which loads the Profile view, your solution would create a new session where `view = 'profile'` and `viewed_id = user-B's-user-id`. You would then continually [renew](#/reference/0/session-endpoints/sessions-session-id-patch) that session every so often until `user-A` navigates away from `user-B`'s profile.
Note that possible values for `viewed_id` are: an `article_id` (only if `view === 'article'`), a `user_id` (only if `view === 'profile'`), an `opportunity_id` (only if `view === 'opportunity'`), or `null`.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Attributes (object)
+ user_id: `"5ec8adf06e38e58770ff2137"` (string, nullable) - A unique immutable MongoDB ID representing the user associated with this session or `null` if this session is unauthenticated.
+ view: `"article"` (string) - The view this session is associated with. Possible values are: `"article"`, `"profile"`, `"opportunity"`, `"admin"`, `"auth"`, or `"home"`.
+ viewed_id: `"5ec8adf06e38137ff2e58770"` (string, nullable) - A unique immutable MongoDB ID corresponding to the `view` item associated with this session, or `null`.
+ Body
{
"user_id": null,
"view": "auth",
"viewed_id": null
}
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ `session_id` (string) - A unique immutable MongoDB ID representing the newly created active session.
+ Body
{
"success": true,
"session_id": "5ec8adf06e38137ff2e58648"
}
### /sessions/:session_id (GET) [GET /sessions/{session_id}]
Retrieve a session by their `session_id`.
Example usage: if `user-A` clicks a link to `user-B`'s profile, which loads the Profile view, there exists a session (`session_id`) where `view = 'profile'` and `viewed_id = user-B's-user-id`. This session would be continually [renewed](#/reference/0/session-endpoints/sessions-session-id-patch) until `user-A` navigates away from `user-B`'s profile.
Note that possible values for `viewed_id` are: an `article_id` (only if `view === 'article'`), a `user_id` (only if `view === 'profile'`), an `opportunity_id` (only if `view === 'opportunity'`), or `null`.
+ Parameters
+ `session_id`: `5eee34b3ca37750008547375` (session_id) - <span style="color: darkred">[required]</span> ID of the session.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ session (Session) - The requested session object.
+ Body
{
"success": true,
"session": {
"session_id": "5ec8adf06e38137ff2e58648",
"user_id": null,
"view": "auth",
"viewed_id": null,
"createdAt": 1579345900770,
"updatedAt": 1579345900770
}
}
### /sessions/:session_id (PATCH) [PATCH /sessions/{session_id}]
Renew an active session to indicate that a client (user) is still accessing a view. Renewing an active session resets the 30-second expiry period.
> Hint: your solution should keep renewing the same session every so often until the client navigates away from the current view, closes the browser, etc. If the client navigates from one URL to another without changing views, your solution should still create a new session instead of renewing the existing one.
+ Parameters
+ `session_id`: `5eee34b3ca37750008547375` (session_id) - <span style="color: darkred">[required]</span> ID of the session.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ Body
{
"success": true
}
### /sessions/:session_id (DELETE) [DELETE /sessions/{session_id}]
Delete (manually expire) an active session.
+ Parameters
+ `session_id`: `5eee34b3ca37750008547375` (session_id) - <span style="color: darkred">[required]</span> ID of the session.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ Body
{
"success": true
}
## User Endpoints [/users]
These endpoints deal with [CRUD operations](https://nordicapis.com/crud-vs-rest-whats-the-difference) on users.
- [/users (GET)](#/reference/0/user-endpoints/users-get)
- [/users (POST)](#/reference/0/user-endpoints/users-post)
- [/users/:user_id (GET)](#/reference/0/user-endpoints/users-user-id-get)
- [/users/:username (GET)](#/reference/0/user-endpoints/users-username-get)
- [/users/:user_id (PATCH)](#/reference/0/user-endpoints/users-user-id-patch)
- [/users/:user_id (DELETE)](#/reference/0/user-endpoints/users-user-id-delete)
- [/users/:user_id/auth (POST)](#/reference/0/user-endpoints/users-user-id-auth-post)
- [/users/:user_id/connections (GET)](#/reference/0/user-endpoints/users-user-id-connections-get)
- [/users/:user_id/connections/:connection_id (POST)](#/reference/0/user-endpoints/users-user-id-connections-connection-id-post)
- [/users/:user_id/connections/:connection_id (DELETE)](#/reference/0/user-endpoints/users-user-id-connections-connection-id-delete)
- [/users/:user_id/sessions (GET)](#/reference/0/user-endpoints/users-user-id-sessions-get)
### /users (GET) [GET /users{?after,updatedAfter}]
Retrieves all users in the system in [FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)) order.
Retrievals are limited to at most 100 results per query. Supports [range queries](https://en.wikipedia.org/wiki/Range_query_(database)) using `after`.
+ Parameters
+ `after` (optional, user_id) - <span style="color: gray">[optional]</span> Return only those results that occur *after* `after` in the result list.
+ `updatedAfter` (optional, number) - <span style="color: gray">[optional]</span> Return only those users with [`updatedAt`](#/data-structures/0/user) greater than `updatedAfter`.
+ Request
+ Headers
Authorization: bearer your-special-api-key-here
content-type: application/json
+ Response 200 (application/json)
See an example (HTTP 200)
+ Attributes (object)
+ success (boolean) - If the request succeeded. Always `true` when status code is 200 and `false` or `undefined` otherwise.
+ users (User) - An array of user objects. Empty if there are no users left to show.
+ Body
{
"success": true,
"users": [
{
"user_id": "5eee34b3ca37750008547372",
"salt": "01048140c7eca69abc74c16dfd418bda",
"username": "dummyuser1",
"email": "[email protected]",
"fullName": "Dummy User One",
"type": "administrator",
"views": 1234,
"sessions": 12,
"sections": {
"about": null,
"experience": [],