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: If you haven't already, enable the Developer Knowledge API in your Google Cloud project.
- 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 documents
Once you have your Developer Knowledge API key, you can start using the API. The following example shows how to search for documents related to "BigQuery":
Save your Developer Knowledge API key to an environment variable:
bash export DEVELOPERKNOWLEDGE_API_KEY="YOUR_API_KEY"ReplaceYOUR_API_KEYwith the API key you generated.Use
curlto call theSearchDocumentsendpoint:curl "https://developerknowledge.googleapis.com/v1alpha/documents:search?query=BigQuery&key=$DEVELOPERKNOWLEDGE_API_KEY"
This command returns a list of document resources that match the query,
including snippets from the content and a name for each document.
Retrieve a document
The response from SearchDocuments contains a list of documents. Each document
has a name field, which you can use to retrieve its full content with
GetDocument.
Copy the name of one of the documents returned by the SearchDocuments call
(for example, documents/developers.google.com/...), save it to an environment
variable, and use curl to call the GetDocument endpoint:
export DOC_NAME="PASTE_DOCUMENT_NAME_HERE"
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.