Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions docs/api/datahub-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,77 @@ Learn more about the GraphQL API:

- **[GraphQL API →](docs/api/graphql/getting-started.md)**

## Python Program Structure for OpenAPI Integration

This section provides a detailed guide on structuring a Python program for creating a `schemaField` for a BigQuery column using DataHub's OpenAPI. This guide is intended for developers looking to programmatically interact with DataHub using Python.

### Prerequisites
- Install the `requests` library: `pip install requests`
- Set up any necessary authentication for interacting with DataHub's API.

### Schema Field Definition
Define a schema field in Python, including necessary attributes and types. Example:
```python
schema_field = {
"fieldPath": "column_name",
"type": {
"type": {
"__type": "StringType"
}
},
"nativeDataType": "STRING"
}
```

### API Request Construction
Construct the API request by setting up headers, defining the payload, and handling the response. Example:
```python
import requests
import json

# Define the DataHub server URL
datahub_url = "http://localhost:8080"

# Define the dataset URN
dataset_urn = "urn:li:dataset:(urn:li:dataPlatform:bigquery,project.dataset.table,PROD)"

# Define the SchemaMetadata aspect
schema_metadata = {
"__type": "SchemaMetadata",
"schemaName": "SampleSchema",
"platform": "urn:li:dataPlatform:bigquery",
"fields": [schema_field]
}

# Define the request payload
payload = {
"aspect": schema_metadata,
"entityType": "dataset",
"entityUrn": dataset_urn
}

# Set up headers, including authentication if needed
headers = {
"Content-Type": "application/json",
# "Authorization": "Bearer YOUR_ACCESS_TOKEN" # Uncomment if authentication is required
}

# Make the POST request to the DataHub OpenAPI endpoint
response = requests.post(f"{datahub_url}/entities", headers=headers, data=json.dumps(payload))

# Check the response
if response.status_code == 200:
print("Schema field created successfully!")
else:
print(f"Failed to create schema field: {response.status_code} - {response.text}")
```

### Error Handling
Implement best practices for error handling when making API requests.

### Authentication
Detailed steps on how to authenticate requests, especially if DataHub requires specific authentication methods.

## DataHub API Comparison

DataHub supports several APIs, each with its own unique usage and format.
Expand Down
20 changes: 20 additions & 0 deletions docs/api/openapi/openapi-usage-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ in the OpenAPI UI are all autogenerated at build time from the PDL models to JSO

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.

### Python Program Structure for OpenAPI Integration

This section provides a detailed guide on structuring a Python program for creating a `schemaField` for a BigQuery column using DataHub's OpenAPI. This guide is intended for developers looking to programmatically interact with DataHub using Python.

#### Prerequisites
- Install the `requests` library using `pip install requests`.
- Set up any necessary authentication for interacting with DataHub's API.

#### Schema Field Definition
- Define a schema field in Python, specifying necessary attributes and types.

#### API Request Construction
- Construct the API request by setting up headers, defining the payload, and handling the response.

#### Error Handling
- Implement best practices for error handling when making API requests.

#### Authentication
- Follow detailed steps to authenticate requests, especially if DataHub requires specific authentication methods.


### Entities (/entities)

Expand Down