client.request() method to make custom API calls. This is useful for:
- Testing new Notion API features before the SDK is updated
- Debugging API responses
- Building custom wrappers or abstractions
- Working with beta or experimental endpoints
The request() Method
Therequest() method is the low-level foundation that all SDK methods use internally.
Method Signature
RequestParameters
Making Custom Requests
GET Request Example
Retrieve a page using the low-level API:POST Request Example
Create a page with a custom request:PATCH Request Example
Update a block:DELETE Request Example
Delete a block:Query Parameters
Pass query parameters using thequery option:
Custom Headers
Add custom headers to your request:The SDK automatically adds required headers like
Notion-Version, Authorization, and Content-Type. You don’t need to include these manually.Request-Level Authentication
Override the client’s default authentication for a single request:OAuth Authentication
For OAuth endpoints, pass client credentials:Type Safety
You can provide a type parameter for the response:Error Handling
Therequest() method throws the same errors as other SDK methods:
Automatic Features
Therequest() method includes all the built-in SDK features:
Automatic Retries
Rate-limited and server error requests are automatically retried with exponential back-off
Request Timeout
Requests timeout after 60 seconds by default (configurable via
timeoutMs in client options)Version Header
The SDK automatically sets the
Notion-Version header to the supported API versionLogging
Requests are logged based on the client’s
logLevel settingInternal Request Flow
Here’s what happens when you callrequest():
- Path Validation - Checks for path traversal attacks (src/Client.ts:239)
- URL Construction - Builds full URL with base URL and query parameters (src/Client.ts:243)
- Headers - Adds authentication, version, and content-type headers (src/Client.ts:245-249)
- Retry Logic - Executes request with automatic retry for transient errors (src/Client.ts:252-258)
- Response Parsing - Parses JSON response or throws typed error (src/Client.ts:430-442)
Practical Example: Custom Endpoint
Imagine Notion releases a new beta endpoint for AI summaries:When to Use request()
Use request() for new or undocumented endpoints
Use request() for new or undocumented endpoints
If Notion releases a new API endpoint that isn’t yet in the SDK, you can call it immediately using
request().Prefer built-in methods for standard endpoints
Prefer built-in methods for standard endpoints
For standard endpoints like
pages.retrieve() or databases.query(), use the built-in methods. They provide better type safety and documentation.Use request() for debugging
Use request() for debugging
The
request() method is useful for debugging API responses or testing parameter combinations.Advanced: Form Data Requests
For file uploads, useformDataParams instead of body:
When using
formDataParams, don’t provide a body. The SDK automatically sets the correct multipart/form-data content type.