You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.We recommend setting the API key as an environment variable in a
.env
file with the name WRITER_API_KEY
.Overview
Adding URLs to your Knowledge Graph enables you to:- Automatically extract content from websites
- Index web pages for Knowledge Graph queries
- Process single pages or entire sub-pages
- Monitor the status of URL processing
- Exclude specific URLs from processing
Add URLs to a Knowledge Graph
To add web connector URLs to your Knowledge Graph, use the PUT endpoint to update the graph with the URLs you want to process. This endpoint allows you to add, update, or remove URLs from your Knowledge Graph.You can only add URLs to a Knowledge Graph with the
type
set to web
. To create a Knowledge Graph with the web
type, you must create the Knowledge Graph in AI Studio and select “Add Website” as the way you want to add content to the Knowledge Graph. See Setting up Knowledge Graph web connectors for more information.You can see the type of a Knowledge Graph in the Knowledge Graph details or in the Knowledge Graph list endpoints.Request structure
The
urls
array in your request replaces the entire existing list of URLs attached to the Knowledge Graph. To add a new URL, include both the existing URLs and the new one in your request. To remove a URL, send a request with all URLs except the one you want to remove.urls
array in your request body. Each URL object has the following parameters:
Parameter | Type | Description |
---|---|---|
url | string | The URL you want to add to your Knowledge Graph |
type | string | How you want to process the URL: either single_page (just this URL) or sub_pages (this URL and linked pages) |
exclude_urls | array | Optional. Any URLs you want to exclude from processing if type is sub_pages |
Response structure
After you update the Knowledge Graph, you see the status of each URL in thestatus
object. The status
object has the following parameters:
Parameter | Type | Description |
---|---|---|
status | string | The current processing status: validating , success , or error |
error_type | string | If there was an error, what type of error occurred |
Possible error types
If URL processing fails, you may see these error types:invalid_url
: The URL format is not validnot_searchable
: The content cannot be accessed or processednot_found
: The URL returns a 404 errorpaywall_or_login_page
: The content requires authenticationunexpected_error
: An unspecified error occurred
Usage examples
The following examples show how to add a web connector URL to a Knowledge Graph and monitor its processing status.Add a web connector URL
This example adds a web connector URL to a Knowledge Graph. It first retrieves the Knowledge Graph to see the current URLs and then adds a new URL to the Knowledge Graph. Note that this operation replaces the entire list of URLs attached to the Knowledge Graph, which is why it is important to retrieve the existing list of URLs first.Delete all URLs from a Knowledge Graph
To delete all URLs from a Knowledge Graph, you can send a request with an emptyurls
array.