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

Enable the API

  1. Open the Developer Knowledge API page in the Google APIs library.
  2. Check that you have the correct project selected in which you intend to use the API.
  3. Click Enable. No specific IAM roles are required to enable or use the API.

Create and secure the API key

  1. In the Google Cloud console for the project in which you enabled the API, go to the Credentials page.
  2. Click Create credentials, and then select API key from the menu. The API key created dialog displays the string for your newly created key.
  3. Click Edit API key.
  4. In the Name field, provide a name for the key.
  5. Under API restrictions, select Restrict key.
  6. From the Select APIs list, enable Developer Knowledge API and click OK.
    • Note: If you just enabled the Developer Knowledge API, there may be a delay before it appears in the Select APIs list.
  7. Click Save.

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