To initiate the process of transferring a temporarily-hosted public file into your Notion workspace, use the Create a file upload with a mode
of "external_url"
, a filename
, and the external_url
itself:
curl --request POST \
--url 'https://api.notion.com/v1/file_uploads' \
-H 'Authorization: Bearer ntn_****' \
-H 'Content-Type: application/json' \
-H 'Notion-Version: <<latestNotionVersion>>' \
--data '{
"mode": "external_url",
"external_url": "https://example.com/image.png",
"filename": "image.png"
}'
At this step, Notion will return a validation_error
(HTTP 400) if any of the following are true:
Content-Type
header for Notion to verify as part of a quick HEAD
HTTPS request.Content-Length
header (size) of the file at the external URL exceeds your workspace’s per-file size limit.After Step 1, Notion begins processing the file import asynchronously. To wait for the upload to finish, your integration can do one of the following:
status
changes from pending
to uploaded
(or failed
).file_upload.complete
file_upload.upload_failed
data[file_import_result]
object for error codes and messages to help troubleshoot.entity
of the webhook payload will contain a type
of "file_upload"
and an id
containing the ID of the FileUpload from Step 1.Screenshot of webhook settings in the Notion creator profile integration settings page.
The outcome of the file import is recorded on the File Upload object. If the import fails, the status changes to failed
. If it succeeds, the status changes to uploaded
.
For example, in response to a file_upload.upload_failed
webhook, your system can read the data.file_import_result.error
from the webhook response, or use the Retrieve a file upload API and check the file_import_result.error
to debug the import failure:
// GET /v1/file_uploads/:file_upload_id
// --- RETURNS -->
{
"object": "file_upload",
// ...
"status": "failed",
"file_import_result": {
"type": "error",
"error": {
"type": "validation_error",
"code": "file_upload_invalid_size",
"message": "The file size is not within the allowed limit of 5 MiB. Please try again with a new file upload.",
"parameter": null,
"status_code": null
},
}
}
The file_import_result
object contains details on the success
or error
. In this example, the problem is a file size validation issue that wasn’t caught during Step 1—potentially because the external host did not provide a Content-Length
header for Notion to validate with a HEAD
request. The same file size limits of 5 MiB for a free workspace and 5 GiB for a paid workspace apply to external URL mode.
A file upload with a status of failed
cannot be reused, and a new one must be created.
Using its ID, attach the File Upload (for example, to a block, page, or database) within one hour of creating it to avoid expiry.
Updated about 2 months ago
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4