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
- Open the Developer Knowledge API page in the Google APIs library.
- Check that you have the correct project selected in which you intend to use the API.
- Click Enable. No specific IAM roles are required to enable or use the API.
Create and secure the API key
- In the Google Cloud console for the project in which you enabled the API, go to the Credentials page.
- Click Create credentials, and then select API key from the menu. The API key created dialog displays the string for your newly created key.
- Click Edit API key.
- In the Name field, provide a name for the key.
- Under API restrictions, select Restrict key.
-
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.
- 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":
Save your Developer Knowledge API key to an environment variable:
export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"Replace
YOUR_API_KEYwith the API key you generated.Use
curlto call thesearchDocumentChunksendpoint: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
- Explore the Corpus reference to see the full list of included documentation.
- See the API reference documentation for more details on API methods and parameters.