Quickstart: Get started with the Developer Knowledge API

This guide shows you how to get started with the Developer Knowledge API. You'll learn how to enable the Developer Knowledge API, get an API key, and make your first API calls to search for and retrieve developer documentation.

Before you begin

  1. Enable the API: If you haven't already, enable the Developer Knowledge API in your Google Cloud project.
  2. Get an API key: You need a Developer Knowledge API key to authenticate your requests. Follow these instructions to create an API key. Remember to restrict your API key for security.

Search for document chunks

Once you have your Developer Knowledge API key, you can start using the API. The following example shows how to search for document chunks related to "BigQuery":

  1. Save your Developer Knowledge API key to an environment variable:

    export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"
    

    Replace YOUR_API_KEY with the API key you generated.

  2. Use curl to call the searchDocumentChunks endpoint:

    curl "https://developerknowledge.googleapis.com/v1alpha/documents:searchDocumentChunks?query=BigQuery&key=$DEVELOPERKNOWLEDGE_API_KEY"
    

This command returns a list of document chunks that match the query, including snippets from the content and a parent for each document.

Retrieve a document

The response from searchDocumentChunks contains a list of document chunks. Each document chunk has a parent field, which you can use to retrieve the document's full content with GetDocument.

Copy the parent of one of the document chunks returned by the searchDocumentChunks call (for example, documents/developers.google.com/...), save it to an environment variable, and use curl to call the GetDocument endpoint:

export DOC_NAME="DOCUMENT_NAME"
curl "https://developerknowledge.googleapis.com/v1alpha/$DOC_NAME?key=$DEVELOPERKNOWLEDGE_API_KEY"

This returns the full Markdown content of the specified document.

What's next