forked from technologiestiftung/giessdenkiez-de-postgres-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.http
More file actions
422 lines (294 loc) · 10.4 KB
/
api.http
File metadata and controls
422 lines (294 loc) · 10.4 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
@SUPABASE_URL = http://localhost:54321
@SUPABASE_ANON_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
@SUPABASE_SERVICE_ROLE_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
# --------------------------------------------------
@protocol = http
@host = localhost
@port = 8080
@API_HOST = {{protocol}}://{{host}}:{{port}}
@TREE_ID = _2100186a5c
@USER_ID = auth0|abc
@USER_NAME = foo
#SUPABASE VARS
@SUPABASE_USER_EMAIL = [email protected]
@SUPABASE_USER_PASSWORD = 1234567890
@SUPABASE_USER_UUID = db640d6c-1ac9-4a4d-accc-0adacbf6d9ad
@SUPABASE_USER_NAME = someone
@SUPABASE_USER_ACCESS_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjc5NDE4Mzc1LCJzdWIiOiI2NmE2ZWNjZS1hZDNhLTRkODctOTIzZS02OTFhMzFhYTMyNjMiLCJlbWFpbCI6ImZhYmlhbm1vcm9uemlyZmFzQHByb3Rvbm1haWwuY2giLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJwYXNzd29yZCIsInRpbWVzdGFtcCI6MTY3OTQxNDc3NX1dLCJzZXNzaW9uX2lkIjoiOWYxYWM4OWItYTU4NC00Mjg5LWIxYWItY2IxNTBmYWZlMmVkIn0.QKf89g4ASbyC4txyHBWh7A_-nQyL93uY694S1Wm8TIY
# @API_HOST = https://giessdenkiez-de-postgres-api-git-dev-technologiestiftung1.vercel.app
# These needs a .env in the root of the project
# you get these variables from auth0
@audience = {{$dotenv audience}}
@issuer = {{$dotenv issuer}}
@jwksuri = {{$dotenv jwksuri}}
@client_id = {{$dotenv client_id}}
@client_secret = {{$dotenv client_secret}}
# the token below is obtained from the
# request to the token issuer
# https://YOUR-tenant.eu.auth0.com/oauth/token
# see section POST AUTH
@token = {{$dotenv token}}
##### ####### #######
# # # #
# # #
# #### ##### #
# # # #
# # # #
##### ####### #
### Healthcheck
GET {{API_HOST}}
### v3
GET {{API_HOST}}/v3
### GET tree by its id byid ✓
GET {{API_HOST}}/get/byid&id={{TREE_ID}}
### GET a list of all waterd trees ✓
GET {{API_HOST}}/get/watered
### GET list of trees from an list of ids ✓
GET {{API_HOST}}/get/treesbyids&tree_ids={{TREE_ID}},_21002949fc
### GET a list of trees with the properities ✓
# adopted (how many users)
# waterd how often in the last 30days
GET {{API_HOST}}/get/wateredandadopted
### GET a list of trees with the properities ✓
# adopted (how many users)
# waterd how often in the last 30days
GET {{API_HOST}}/get/wateredandadopted?limit=4&offset=5
### get all trees with id, lat, lon, radolan_sum ✓
# with pagination
GET {{API_HOST}}/get/all&limit=4&offset=5
### get all trees
GET {{API_HOST}}/get/all
### GET trees by age
GET {{API_HOST}}/get/byage&start=1800&end=2023
### GET trees by age
GET {{API_HOST}}/get/byage&start=1800&end=2023&limit=10000&offset=0
### GET count of trees by age ✓
GET {{API_HOST}}/get/countbyage&start=1800&end=2023
########################
#
# SUPABASE AUTH
#
#########################
### Signup
POST {{SUPABASE_URL}}/auth/v1/signup
apikey: {{SUPABASE_ANON_KEY}}
Content-Type: application/json
{
"email": "{{SUPABASE_USER_EMAIL}}",
"password": "{{SUPABASE_USER_PASSWORD}}"
}
### Login
POST {{SUPABASE_URL}}/auth/v1/token?grant_type=password
apikey: {{SUPABASE_ANON_KEY}}
Content-Type: application/json
{
"email": "{{SUPABASE_USER_EMAIL}}",
"password": "{{SUPABASE_USER_PASSWORD}}"
}
### Login with magic link
# look ont oinbucket of the email
# http://localhost:54324
POST {{SUPABASE_URL}}/auth/v1/magiclink
apikey: {{SUPABASE_ANON_KEY}}
Content-Type: application/json
{
"email": "{{SUPABASE_USER_EMAIL}}"
}
### Get user JSON
GET {{SUPABASE_URL}}/auth/v1/user
apikey: {{SUPABASE_ANON_KEY}}
Content-Type: application/json
Authorization: Bearer {{SUPABASE_USER_ACCESS_TOKEN}}
### Password recovery
# in local developement look into the inbuckt of the email
# http://localhost:54324
# This will send you to http://localhost:3000 ???
# with a token und the recovery url Param
POST {{SUPABASE_URL}}/auth/v1/recover
apikey: {{SUPABASE_ANON_KEY}}
Content-Type: application/json
{
"email": "{{SUPABASE_USER_EMAIL}}"
}
### Update the user data password and/or email
# data is optional
PUT {{SUPABASE_URL}}/auth/v1/user
apikey: {{SUPABASE_ANON_KEY}}
Authorization: Bearer {{SUPABASE_USER_ACCESS_TOKEN}}
Content-Type: application/json
{
"email": "{{SUPABASE_USER_EMAIL}}",
"password": "{{SUPABASE_USER_PASSWORD}}",
"data": {
"key": "value"
}
}
### Logout
POST {{SUPABASE_URL}}/auth/v1/logout
apikey {{SUPABASE_ANON_KEY}}
Authorization: Bearer {{SUPABASE_USER_ACCESS_TOKEN}}
########################
#
# SUPABASE AUTH END
#
#########################
##### ####### #######
# # # #
# # #
# #### ##### #
# # # #
# # # #
##### ####### #
#
# #
# #
# #
#######
# #
# #
####### ####### # # ####### # #
# # # # # # ## #
# # # # # # # # #
# # # ### ##### # # #
# # # # # # # # #
# # # # # # # ##
# ####### # # ####### # #
### POST to the token issuer and get an JWT token
# for authenticated requests
POST {{issuer}}oauth/token
Content-Type: application/json
{
"client_id": "{{client_id}}",
"client_secret": "{{client_secret}}",
"audience": "{{audience}}",
"grant_type": "client_credentials"
}
##### ####### #######
# # # #
# # #
# #### ##### #
# # # #
# # # #
##### ####### #
# # # ####### # #
# # # # # # #
# # # # # # #
# # # # # #######
####### # # # # #
# # # # # # #
# # ##### # # #
### GET trees that where watered by aq specific user ✓
GET {{API_HOST}}/get/wateredbyuser&uuid={{USER_ID}}
Authorization: Bearer {{token}}
### GET check if a tree is adopted by a specific user ✓
{{API_HOST}}/get/istreeadopted&uuid={{USER_ID}}&id={{TREE_ID}}
Authorization: Bearer {{token}}
### GET trees that are adopted by a specific user ✓
{{API_HOST}}/get/adopted&uuid={{USER_ID}}
Authorization: Bearer {{token}}
### GET the last watering of a specific tree with all the users ✓
{{API_HOST}}/get/lastwatered&id={{TREE_ID}}
###### ####### ##### #######
# # # # # # #
# # # # # #
###### # # ##### #
# # # # #
# # # # # #
# ####### ##### #
# # # ####### # #
# # # # # # #
# # # # # # #
# # # # # #######
####### # # # # #
# # # # # # #
# # ##### # # #
### POST water a tree
POST {{API_HOST}}/post/water
Authorization: Bearer {{SUPABASE_USER_ACCESS_TOKEN}}
Content-Type: application/json
{
"timestamp":"{{$datetime "YYYY-MM-DD HH:mm:ss"}}",
"tree_id":"{{TREE_ID}}",
"uuid": "{{USER_ID}}",
"username":"{{USER_NAME}}",
"amount": 100
}
### Adopt a tree
POST {{API_HOST}}/post/adopt
Authorization: Bearer {{token}}
Content-Type: application/json
{
"tree_id":"{{TREE_ID}}",
"uuid": "{{USER_ID}}"
}
###### ####### # ####### ####### #######
# # # # # # #
# # # # # # #
# # ##### # ##### # #####
# # # # # # #
# # # # # # #
###### ####### ####### ####### # #######
# # # ####### # #
# # # # # # #
# # # # # # #
# # # # # #######
####### # # # # #
# # # # # # #
# # ##### # # #
### DELETE a tree adoption
DELETE {{API_HOST}}/delete/unadopt
Authorization: Bearer {{token}}
Content-Type: application/json
{
"tree_id":"{{TREE_ID}}",
"uuid": "{{USER_ID}}"
}
### DELETE a tree watering
DELETE {{API_HOST}}/delete/unwater
Authorization: Bearer {{token}}
Content-Type: application/json
{
"tree_id":"{{TREE_ID}}",
"uuid": "{{USER_ID}}"
"watering_id": 1
}
# ██████ ██ ██ ██████ ███████
# ██ ██ ██ ██ ██ ██ ██
# ██████ ██ ██ ██████ █████
# ██ ██ ██ ██ ██ ██
# ██ ██████ ██ ██ ███████
# ███████ ██ ██ ██████ █████ ██████ █████ ███████ ███████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ███████ ██ ██ ██████ ███████ ██████ ███████ ███████ █████
# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
# ███████ ██████ ██ ██ ██ ██████ ██ ██ ███████ ███████
# █████ ██████ ██
# ██ ██ ██ ██ ██
# ███████ ██████ ██
# ██ ██ ██ ██
# ██ ██ ██ ██
### SUPABASE REST API (anon) (swagger)
GET {{SUPABASE_URL}}/rest/v1/
apikey: {{SUPABASE_ANON_KEY}}
### HEAD to trees_watered (anon)
# Use this to get the right amount of items returned
HEAD {{SUPABASE_URL}}/rest/v1/trees_watered
apikey: {{SUPABASE_ANON_KEY}}
Authorization: Bearer {{SUPABASE_SERVICE_ROLE_KEY}}
Range-Unit: items
Range: 33-300
Prefer: count=exact
### GET trees_watered (sudo mode since RLS is in effect)
GET {{SUPABASE_URL}}/rest/v1/trees_watered
apikey: {{SUPABASE_ANON_KEY}}
Authorization: Bearer {{SUPABASE_SERVICE_ROLE_KEY}}
### RPC get_watered_and_adopted
GET {{SUPABASE_URL}}/rest/v1/rpc/get_watered_and_adopted
apikey: {{SUPABASE_ANON_KEY}}
Range-Unit: items
Prefer: count=exact
### DELETE an account
POST {{SUPABASE_URL}}/rest/v1/rpc/remove_account
apikey: {{SUPABASE_ANON_KEY}}
Authorization: Bearer {{SUPABASE_USER_ACCESS_TOKEN}}
Content-Type: application/json