File size: 26,800 Bytes
5ebe318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# DataHub OpenAPI Guide

## Why OpenAPI

The OpenAPI standard is a widely used documentation and design approach for REST-ful APIs.
To make it easier to integrate with DataHub, we are publishing an OpenAPI based set of endpoints.

Read [the DataHub API overview](../datahub-apis.md) to understand the rationale behind the different API-s and when to use each one.

## Locating the OpenAPI endpoints

Currently, the OpenAPI endpoints are isolated to a servlet on GMS and are automatically deployed with a GMS server.
The servlet includes auto-generation of an OpenAPI UI, also known as Swagger, which is available at **GMS_SERVER_HOST:GMS_PORT/openapi/swagger-ui/index.html**. For example, the Quickstart running locally exposes this at http://localhost:8080/openapi/swagger-ui/index.html.

This is also exposed through DataHub frontend as a proxy with the same endpoint, but GMS host and port replaced with DataHub frontend's url ([Local Quickstart link](http://localhost:9002/openapi/swagger-ui/index.html)) and is available in the top right dropdown under the user profile picture as a link.
![image](https://github.com/datahub-project/static-assets/blob/main/imgs/api/openapi/openapi_dropdown.png?raw=true)


Note that it is possible to get the raw JSON or YAML formats of the OpenAPI spec by navigating to [**BASE_URL/openapi/v3/api-docs**](http://localhost:9002/openapi/v3/api-docs) or [**BASE_URL/openapi/v3/api-docs.yaml**](http://localhost:9002/openapi/v3/api-docs.yaml).
The raw forms can be fed into codegen systems to generate client side code in the language of your choice that support the OpenAPI format. We have noticed varying degrees of maturity with different languages in these codegen systems so some may require customizations to be fully compatible.

The OpenAPI UI includes explorable schemas for request and response objects that are fully documented. The models used
in the OpenAPI UI are all autogenerated at build time from the PDL models to JSON Schema compatible Java Models.

## Understanding the OpenAPI endpoints

While the full OpenAPI spec is always available at [**GMS_SERVER_HOST:GMS_PORT/openapi/swagger-ui/index.html**](http://localhost:8080/openapi/swagger-ui/index.html), here's a quick overview of the main OpenAPI endpoints and their purpose.


### Entities (/entities)

The entities endpoints are intended for reads and writes to the metadata graph. The entire DataHub metadata model is available for you to write to (as entity, aspect pairs) or to read an individual entity's metadata from. See [examples](#entities-entities-endpoint) below.

### Relationships (/relationships)

The relationships endpoints are intended for you to query the graph, to navigate relationships from one entity to others. See [examples](#relationships-relationships-endpoint) below.

### Timeline (/timeline)

The timeline endpoints are intended for querying the versioned history of a given entity over time. For example, you can query a dataset for all schema changes that have happened to it over time, or all documentation changes that have happened to it. See [this](../../dev-guides/timeline.md) guide for more details.

### Platform (/platform)

Even lower-level API-s that allow you to write metadata events into the DataHub platform using a standard format.


### Example Requests

#### Entities (/entities) endpoint

##### POST

```shell
curl --location --request POST 'localhost:8080/openapi/entities/v1/' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJhY3RvclR5cGUiOiJVU0VSIiwiYWN0b3JJZCI6ImRhdGFodWIiLCJ0eXBlIjoiUEVSU09OQUwiLCJ2ZXJzaW9uIjoiMSIsImV4cCI6MTY1MDY2MDY1NSwianRpIjoiM2E4ZDY3ZTItOTM5Yi00NTY3LWE0MjYtZDdlMDA1ZGU3NjJjIiwic3ViIjoiZGF0YWh1YiIsImlzcyI6ImRhdGFodWItbWV0YWRhdGEtc2VydmljZSJ9.pp_vW2u1tiiTT7U0nDF2EQdcayOMB8jatiOA8Je4JJA' \
--data-raw '[
    {
        "aspect": {
            "__type": "SchemaMetadata",
            "schemaName": "SampleHdfsSchema",
            "platform": "urn:li:dataPlatform:platform",
            "platformSchema": {
                "__type": "MySqlDDL",
                "tableSchema": "schema"
            },
            "version": 0,
            "created": {
                "time": 1621882982738,
                "actor": "urn:li:corpuser:etl",
                "impersonator": "urn:li:corpuser:jdoe"
            },
            "lastModified": {
                "time": 1621882982738,
                "actor": "urn:li:corpuser:etl",
                "impersonator": "urn:li:corpuser:jdoe"
            },
            "hash": "",
            "fields": [
                {
                    "fieldPath": "county_fips_codefg",
                    "jsonPath": "null",
                    "nullable": true,
                    "description": "null",
                    "type": {
                        "type": {
                            "__type": "StringType"
                        }
                    },
                    "nativeDataType": "String()",
                    "recursive": false
                },
                {
                    "fieldPath": "county_name",
                    "jsonPath": "null",
                    "nullable": true,
                    "description": "null",
                    "type": {
                        "type": {
                            "__type": "StringType"
                        }
                    },
                    "nativeDataType": "String()",
                    "recursive": false
                }
            ]
        },
        "entityType": "dataset",
        "entityUrn": "urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)"
    }
]'
```

##### GET

```shell
curl --location --request GET 'localhost:8080/openapi/entities/v1/latest?urns=urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)&aspectNames=schemaMetadata' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJhY3RvclR5cGUiOiJVU0VSIiwiYWN0b3JJZCI6ImRhdGFodWIiLCJ0eXBlIjoiUEVSU09OQUwiLCJ2ZXJzaW9uIjoiMSIsImV4cCI6MTY1MDY2MDY1NSwianRpIjoiM2E4ZDY3ZTItOTM5Yi00NTY3LWE0MjYtZDdlMDA1ZGU3NjJjIiwic3ViIjoiZGF0YWh1YiIsImlzcyI6ImRhdGFodWItbWV0YWRhdGEtc2VydmljZSJ9.pp_vW2u1tiiTT7U0nDF2EQdcayOMB8jatiOA8Je4JJA'
```

##### DELETE

```shell
curl --location --request DELETE 'localhost:8080/openapi/entities/v1/?urns=urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)&soft=true' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJhY3RvclR5cGUiOiJVU0VSIiwiYWN0b3JJZCI6ImRhdGFodWIiLCJ0eXBlIjoiUEVSU09OQUwiLCJ2ZXJzaW9uIjoiMSIsImV4cCI6MTY1MDY2MDY1NSwianRpIjoiM2E4ZDY3ZTItOTM5Yi00NTY3LWE0MjYtZDdlMDA1ZGU3NjJjIiwic3ViIjoiZGF0YWh1YiIsImlzcyI6ImRhdGFodWItbWV0YWRhdGEtc2VydmljZSJ9.pp_vW2u1tiiTT7U0nDF2EQdcayOMB8jatiOA8Je4JJA'
```

#### Postman Collection

Collection includes a POST, GET, and DELETE for a single entity with a SchemaMetadata aspect

```json
{
  "info": {
    "_postman_id": "87b7401c-a5dc-47e4-90b4-90fe876d6c28",
    "name": "DataHub OpenAPI",
    "description": "A description",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "entities/v1",
      "item": [
        {
          "name": "post Entities 1",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "[\n    {\n        \"aspect\": {\n            \"__type\": \"SchemaMetadata\",\n            \"schemaName\": \"SampleHdfsSchema\",\n            \"platform\": \"urn:li:dataPlatform:platform\",\n            \"platformSchema\": {\n                \"__type\": \"MySqlDDL\",\n                \"tableSchema\": \"schema\"\n            },\n            \"version\": 0,\n            \"created\": {\n                \"time\": 1621882982738,\n                \"actor\": \"urn:li:corpuser:etl\",\n                \"impersonator\": \"urn:li:corpuser:jdoe\"\n            },\n            \"lastModified\": {\n                \"time\": 1621882982738,\n                \"actor\": \"urn:li:corpuser:etl\",\n                \"impersonator\": \"urn:li:corpuser:jdoe\"\n            },\n            \"hash\": \"\",\n            \"fields\": [\n                {\n                    \"fieldPath\": \"county_fips_codefg\",\n                    \"jsonPath\": \"null\",\n                    \"nullable\": true,\n                    \"description\": \"null\",\n                    \"type\": {\n                        \"type\": {\n                            \"__type\": \"StringType\"\n                        }\n                    },\n                    \"nativeDataType\": \"String()\",\n                    \"recursive\": false\n                },\n                {\n                    \"fieldPath\": \"county_name\",\n                    \"jsonPath\": \"null\",\n                    \"nullable\": true,\n                    \"description\": \"null\",\n                    \"type\": {\n                        \"type\": {\n                            \"__type\": \"StringType\"\n                        }\n                    },\n                    \"nativeDataType\": \"String()\",\n                    \"recursive\": false\n                }\n            ]\n        },\n        \"aspectName\": \"schemaMetadata\",\n        \"entityType\": \"dataset\",\n        \"entityUrn\": \"urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)\"\n    }\n]",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/openapi/entities/v1/",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "openapi",
                "entities",
                "v1",
                ""
              ]
            }
          },
          "response": [
            {
              "name": "OK",
              "originalRequest": {
                "method": "POST",
                "header": [],
                "body": {
                  "mode": "raw",
                  "raw": "[\n  {\n    \"aspect\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"aspectName\": \"aliquip ipsum tempor\",\n    \"entityType\": \"ut est\",\n    \"entityUrn\": \"enim in nulla\",\n    \"entityKeyAspect\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n  },\n  {\n    \"aspect\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"aspectName\": \"ipsum id\",\n    \"entityType\": \"deser\",\n    \"entityUrn\": \"aliqua sit\",\n    \"entityKeyAspect\": {\n      \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n  }\n]",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/entities/v1/",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "entities",
                    "v1",
                    ""
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "[\n  \"c\",\n  \"labore dolor exercitation in\"\n]"
            }
          ]
        },
        {
          "name": "delete Entities",
          "request": {
            "method": "DELETE",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/openapi/entities/v1/?urns=urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)&soft=true",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "openapi",
                "entities",
                "v1",
                ""
              ],
              "query": [
                {
                  "key": "urns",
                  "value": "urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)",
                  "description": "(Required) A list of raw urn strings, only supports a single entity type per request."
                },
                {
                  "key": "urns",
                  "value": "labore dolor exercitation in",
                  "description": "(Required) A list of raw urn strings, only supports a single entity type per request.",
                  "disabled": true
                },
                {
                  "key": "soft",
                  "value": "true",
                  "description": "Determines whether the delete will be soft or hard, defaults to true for soft delete"
                }
              ]
            }
          },
          "response": [
            {
              "name": "OK",
              "originalRequest": {
                "method": "DELETE",
                "header": [],
                "url": {
                  "raw": "{{baseUrl}}/entities/v1/?urns=urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)&soft=true",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "entities",
                    "v1",
                    ""
                  ],
                  "query": [
                    {
                      "key": "urns",
                      "value": "urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)"
                    },
                    {
                      "key": "urns",
                      "value": "officia occaecat elit dolor",
                      "disabled": true
                    },
                    {
                      "key": "soft",
                      "value": "true"
                    }
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "[\n    {\n        \"rowsRolledBack\": [\n            {\n                \"urn\": \"urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)\"\n            }\n        ],\n        \"rowsDeletedFromEntityDeletion\": 1\n    }\n]"
            }
          ]
        },
        {
          "name": "get Entities",
          "protocolProfileBehavior": {
            "disableUrlEncoding": false
          },
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/openapi/entities/v1/latest?urns=urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)&aspectNames=schemaMetadata",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "openapi",
                "entities",
                "v1",
                "latest"
              ],
              "query": [
                {
                  "key": "urns",
                  "value": "urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)",
                  "description": "(Required) A list of raw urn strings, only supports a single entity type per request."
                },
                {
                  "key": "urns",
                  "value": "labore dolor exercitation in",
                  "description": "(Required) A list of raw urn strings, only supports a single entity type per request.",
                  "disabled": true
                },
                {
                  "key": "aspectNames",
                  "value": "schemaMetadata",
                  "description": "The list of aspect names to retrieve"
                },
                {
                  "key": "aspectNames",
                  "value": "labore dolor exercitation in",
                  "description": "The list of aspect names to retrieve",
                  "disabled": true
                }
              ]
            }
          },
          "response": [
            {
              "name": "OK",
              "originalRequest": {
                "method": "GET",
                "header": [],
                "url": {
                  "raw": "{{baseUrl}}/entities/v1/latest?urns=urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)&aspectNames=schemaMetadata",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "entities",
                    "v1",
                    "latest"
                  ],
                  "query": [
                    {
                      "key": "urns",
                      "value": "non exercitation occaecat",
                      "disabled": true
                    },
                    {
                      "key": "urns",
                      "value": "urn:li:dataset:(urn:li:dataPlatform:platform,testSchemaIngest,PROD)"
                    },
                    {
                      "key": "aspectNames",
                      "value": "non exercitation occaecat",
                      "disabled": true
                    },
                    {
                      "key": "aspectNames",
                      "value": "schemaMetadata"
                    }
                  ]
                }
              },
              "status": "OK",
              "code": 200,
              "_postman_previewlanguage": "json",
              "header": [
                {
                  "key": "Content-Type",
                  "value": "application/json"
                }
              ],
              "cookie": [],
              "body": "{\n    \"responses\": {\n        \"urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)\": {\n            \"entityName\": \"dataset\",\n            \"urn\": \"urn:li:dataset:(urn:li:dataPlatform:hive,SampleHiveDataset,PROD)\",\n            \"aspects\": {\n                \"datasetKey\": {\n                    \"name\": \"datasetKey\",\n                    \"type\": \"VERSIONED\",\n                    \"version\": 0,\n                    \"value\": {\n                        \"__type\": \"DatasetKey\",\n                        \"platform\": \"urn:li:dataPlatform:hive\",\n                        \"name\": \"SampleHiveDataset\",\n                        \"origin\": \"PROD\"\n                    },\n                    \"created\": {\n                        \"time\": 1650657843351,\n                        \"actor\": \"urn:li:corpuser:__datahub_system\"\n                    }\n                },\n                \"schemaMetadata\": {\n                    \"name\": \"schemaMetadata\",\n                    \"type\": \"VERSIONED\",\n                    \"version\": 0,\n                    \"value\": {\n                        \"__type\": \"SchemaMetadata\",\n                        \"schemaName\": \"SampleHiveSchema\",\n                        \"platform\": \"urn:li:dataPlatform:hive\",\n                        \"version\": 0,\n                        \"created\": {\n                            \"time\": 1581407189000,\n                            \"actor\": \"urn:li:corpuser:jdoe\"\n                        },\n                        \"lastModified\": {\n                            \"time\": 1581407189000,\n                            \"actor\": \"urn:li:corpuser:jdoe\"\n                        },\n                        \"hash\": \"\",\n                        \"platformSchema\": {\n                            \"__type\": \"KafkaSchema\",\n                            \"documentSchema\": \"{\\\"type\\\":\\\"record\\\",\\\"name\\\":\\\"SampleHiveSchema\\\",\\\"namespace\\\":\\\"com.linkedin.dataset\\\",\\\"doc\\\":\\\"Sample Hive dataset\\\",\\\"fields\\\":[{\\\"name\\\":\\\"field_foo\\\",\\\"type\\\":[\\\"string\\\"]},{\\\"name\\\":\\\"field_bar\\\",\\\"type\\\":[\\\"boolean\\\"]}]}\"\n                        },\n                        \"fields\": [\n                            {\n                                \"fieldPath\": \"field_foo\",\n                                \"nullable\": false,\n                                \"description\": \"Foo field description\",\n                                \"type\": {\n                                    \"type\": {\n                                        \"__type\": \"BooleanType\"\n                                    }\n                                },\n                                \"nativeDataType\": \"varchar(100)\",\n                                \"recursive\": false,\n                                \"isPartOfKey\": true\n                            },\n                            {\n                                \"fieldPath\": \"field_bar\",\n                                \"nullable\": false,\n                                \"description\": \"Bar field description\",\n                                \"type\": {\n                                    \"type\": {\n                                        \"__type\": \"BooleanType\"\n                                    }\n                                },\n                                \"nativeDataType\": \"boolean\",\n                                \"recursive\": false,\n                                \"isPartOfKey\": false\n                            }\n                        ]\n                    },\n                    \"created\": {\n                        \"time\": 1650610810000,\n                        \"actor\": \"urn:li:corpuser:UNKNOWN\"\n                    }\n                }\n            }\n        }\n    }\n}"
            }
          ]
        }
      ],
      "auth": {
        "type": "bearer",
        "bearer": [
          {
            "key": "token",
            "value": "{{token}}",
            "type": "string"
          }
        ]
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              ""
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              ""
            ]
          }
        }
      ]
    }
  ],
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          ""
        ]
      }
    },
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          ""
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "localhost:8080",
      "type": "string"
    },
    {
      "key": "token",
      "value": "eyJhbGciOiJIUzI1NiJ9.eyJhY3RvclR5cGUiOiJVU0VSIiwiYWN0b3JJZCI6ImRhdGFodWIiLCJ0eXBlIjoiUEVSU09OQUwiLCJ2ZXJzaW9uIjoiMSIsImV4cCI6MTY1MDY2MDY1NSwianRpIjoiM2E4ZDY3ZTItOTM5Yi00NTY3LWE0MjYtZDdlMDA1ZGU3NjJjIiwic3ViIjoiZGF0YWh1YiIsImlzcyI6ImRhdGFodWItbWV0YWRhdGEtc2VydmljZSJ9.pp_vW2u1tiiTT7U0nDF2EQdcayOMB8jatiOA8Je4JJA",
      "type": "default"
    }
  ]
}
```

#### Relationships (/relationships) endpoint

##### GET

**Sample Request**
```shell
curl -X 'GET' \
  'http://localhost:8080/openapi/relationships/v1/?urn=urn%3Ali%3Acorpuser%3Adatahub&relationshipTypes=IsPartOf&direction=INCOMING&start=0&count=200' \
  -H 'accept: application/json'
```

**Sample Response**
```json
{
  "start": 0,
  "count": 2,
  "total": 2,
  "entities": [
    {
      "relationshipType": "IsPartOf",
      "urn": "urn:li:corpGroup:bfoo"
    },
    {
      "relationshipType": "IsPartOf",
      "urn": "urn:li:corpGroup:jdoe"
    }
  ]
}
```

## Programmatic Usage

Programmatic usage of the models can be done through the Java Rest Emitter which includes the generated models. A minimal
Java project for emitting to the OpenAPI endpoints would need the following dependencies (gradle format):

```groovy
dependencies {
    implementation 'io.acryl:datahub-client:<DATAHUB_CLIENT_VERSION>'
    implementation 'org.apache.httpcomponents:httpclient:<APACHE_HTTP_CLIENT_VERSION>'
    implementation 'org.apache.httpcomponents:httpasyncclient:<APACHE_ASYNC_CLIENT_VERSION>'
}
```

### Writing metadata events to the /platform endpoints

The following code emits metadata events through OpenAPI by constructing a list of `UpsertAspectRequest`s. Behind the scenes, this is using the **/platform/entities/v1** endpoint to send metadata to GMS.

```java
import io.datahubproject.openapi.generated.DatasetProperties;
import datahub.client.rest.RestEmitter;
import datahub.event.UpsertAspectRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;


public class Main {
  public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
    RestEmitter emitter = RestEmitter.createWithDefaults();

    List<UpsertAspectRequest> requests = new ArrayList<>();
    UpsertAspectRequest upsertAspectRequest = UpsertAspectRequest.builder()
        .entityType("dataset")
        .entityUrn("urn:li:dataset:(urn:li:dataPlatform:bigquery,my-project.my-other-dataset.user-table,PROD)")
        .aspect(new DatasetProperties().description("This is the canonical User profile dataset"))
        .build();
    UpsertAspectRequest upsertAspectRequest2 = UpsertAspectRequest.builder()
        .entityType("dataset")
        .entityUrn("urn:li:dataset:(urn:li:dataPlatform:bigquery,my-project.another-dataset.user-table,PROD)")
        .aspect(new DatasetProperties().description("This is the canonical User profile dataset 2"))
        .build();
    requests.add(upsertAspectRequest);
    requests.add(upsertAspectRequest2);
    System.out.println(emitter.emit(requests, null).get());
    System.exit(0);
  }
}
```