DataHub APIs

DataHub APIs: Automating Your Metadata Operations

  • Module 12 of Tier 3 User Training — Duration: 45 minutes
  • By the end of this module, you will be able to:
    • Explain when to use the GraphQL API vs. the REST API
    • Write a GraphQL query to search and filter DataHub entities
    • Call the REST API to perform bulk operations
    • Use browser devtools to discover query shapes from the DataHub UI
By the end of this module GraphQL vs. REST: when to use which Write a GraphQL search query Call the REST API for bulk operations Discover query shapes with devtools 45 min

The UI Gets You Started. The API Gets Work Done.

  • The DataHub UI is built for interactive exploration
  • The API is how you automate at scale
  • Common use cases:
    • Bulk-update descriptions across 500 tables after a schema migration
    • Find every asset without an owner and generate a compliance report
    • Programmatically certify datasets after a quality check passes
    • Integrate DataHub metadata into your internal developer portal or data catalog overlay
UI interactive exploration API automate at scale Use cases: bulk description updates · ownership reports automated certification · developer-portal integration

DataHub Exposes Two API Surfaces

  • GraphQL: /api/graphql
  • REST (OpenAPI v3): /openapi/...
  • Both require authentication: Authorization: Bearer <your-token>
  • Personal access tokens are generated in DataHub Settings (Access Tokens)
  • Swagger UI for REST: /openapi/swagger-ui/index.html
  • GraphQL Explorer (interactive playground): /api/graphiql
GraphQL /api/graphql Explorer: /api/graphiql REST (OpenAPI v3) /openapi/v3/entity/... Swagger: /openapi/swagger-ui Bearer token

You Do Not Need to Read the Docs to Learn GraphQL

  • The DataHub UI is almost entirely GraphQL-powered
  • Open browser devtools, go to the Network tab, filter by "graphql"
  • Every UI action fires a real GraphQL query you can copy and adapt
  • The GraphQL Explorer at /api/graphiql lets you run those queries interactively
  • Auto-complete and schema introspection are built in: press Ctrl+Space anywhere in the editor
Brief: Screenshot of browser devtools open alongside the DataHub UI, Network tab active, filter box showing "graphql", with one GraphQL request row selected and its request payload visible in the preview pane.

The Core Read Operation: search

  • search takes an entity type, a query string, and optional filters
  • Filters are key-value pairs: field name and a URN or string value
  • Useful filter fields: domains, tags, platform, owners, glossaryTerms
  • Returns a list of matching entities with whichever fields you request
  • Example: find all datasets in the Finance domain with the Certified tag:
query {
  search(input: {
    type: DATASET,
    query: "*",
    orFilters: [{
      and: [
        { field: "domains", values: ["urn:li:domain:Finance"] },
        { field: "tags", values: ["urn:li:tag:Certified"] }
      ]
    }]
  }) {
    total
    searchResults {
      entity {
        ... on Dataset {
          properties { name }
          platform { name }
          ownership {
            owners {
              owner {
                ... on CorpUser { username }
              }
            }
          }
        }
      }
    }
  }
}
Brief: Screenshot of the GraphQL Explorer at /api/graphiql with this search query typed into the left editor pane and the response JSON visible in the right results pane.

Mutations: Writing Metadata Back to DataHub

  • updateDescription: Set or update the description on any entity
  • addTag / removeTag: Apply or remove a tag from an entity
  • addOwner / removeOwner: Add or remove an owner from an entity
  • All mutations take the entity URN as input
  • Mutations take effect immediately in the production instance you are connected to
  • The GraphQL Explorer will autocomplete mutation argument shapes
updateDescription addTag / removeTag addOwner / removeOwner entity URN + new value

GraphQL Mutations Affect Real Data Immediately

  • DataHub has no "dry run" mode for GraphQL mutations
  • A mutation run against your production instance takes effect immediately
  • There is no undo button
  • Rule: always develop and test mutations on a dev or staging instance first
  • Rule: if you are scripting bulk mutations, run against a small sample (5-10 entities) before scaling up
  • Rule: use search to preview which entities your filters will match before you mutate them
search (preview) mutate one entity verify in UI scale to full batch ⚠ skip straight to 500 entities

The REST API: Built for Bulk

  • Swagger UI: /openapi/swagger-ui/index.html
  • Key endpoints for day-to-day automation:
    • /openapi/v3/entity/{entityType}/{urn}: GET — fetch one entity
    • /openapi/v3/entity/{entityType}: POST — create or update entities; the body is a JSON array, so one call upserts a whole batch
    • /openapi/v3/entity/{entityType}/{urn}: DELETE — remove one entity by URN
  • DELETE removes the entity outright: there is no soft-delete query parameter on this endpoint
Brief: Screenshot of the Swagger UI at /openapi/swagger-ui/index.html with the DELETE /openapi/v3/entity/{entityType}/{urn} endpoint expanded, showing its parameters panel (entityType and urn path parameters).

Match the API Surface to the Job

  • Use GraphQL when:
    • Reading entity metadata (single entity or filtered search)
    • Making a targeted mutation to one or a few entities
    • Exploring what fields are available on an entity type
    • Prototyping: the Explorer gives you instant feedback
  • Use REST when:
    • Upserting more than ~20 entities at once (one POST call, JSON array body)
    • Deleting entities in a script: loop one DELETE call per URN
How many entities? Fewer than ~20 GraphQL: read, targeted mutations, prototyping ~20 or more REST: one-call upsert, looped delete

The acryl-datahub Python SDK

  • Install: pip install acryl-datahub
  • The SDK wraps the REST API with Python classes
  • Key classes:
    • DataHubRestEmitter: connects to your DataHub instance and emits metadata
    • MetadataChangeProposalWrapper: wraps an aspect (description, ownership, tags) in the envelope format DataHub expects
  • When to use the SDK vs. raw REST:
    • SDK: scripting tasks where you want to avoid building JSON payloads by hand
Your Python script acryl-datahub SDK DataHubRestEmitter, MetadataChangeProposalWrapper DataHub REST API

Write Queries and Delete Stale Entities

  • Part 1: GraphQL (20 minutes)
    • Open the GraphQL Explorer at /api/graphiql in the training environment
    • Write a query that returns all Certified datasets in the Finance domain
    • Your result must include: dataset name, platform name, owner username
    • Use the example query in your participant guide as a starting point, then modify it
  • Part 2: REST Delete (10 minutes)
    • You have 3 stale entity URNs on your lab card
Brief: Screenshot of the GraphQL Explorer at /api/graphiql with a search query for Certified datasets in the Finance domain typed into the left editor pane and a results list showing dataset name, platform, and owner fields in the response pane.

Check for Understanding

  • You need to find every dataset in DataHub that has no owner assigned. Which API and which operation do you use?
  • You have a list of 300 deprecated tables in Snowflake that should be removed from DataHub. Which endpoint and which HTTP method do you use to delete them efficiently?
  • You want to add a "Reviewed" tag to a single dataset. You are already in the DataHub UI and want to prototype the mutation before writing a script. What is the fastest way to find the correct GraphQL mutation shape?
  • A colleague says they wrote a mutation script but wants to test it before running it in production. They ask if there is a "preview" mode. What do you tell them?
1. Find assets with no owner 2. Delete 300 stale tables 3. Find a mutation shape fast 4. Is there a preview mode?