I’m working with the Notion API Beta and I’ve run into a problem. I’m trying to get data from a table that has a ‘Files & media’ property. The API gives me the names of the uploaded files but not their URLs. How can I actually access these files? Here’s what the API response looks like:
{
"MediaField": {
"id": "abc123",
"type": "files",
"files": [
{
"name": "vacation_photo_2023.jpg"
}
]
}
}
Does anyone know how to get the actual file URLs from this data? I’m stumped and could really use some help. Thanks!
I’ve been there, Sophia. The Notion API can be tricky with file handling. Here’s what worked for me:
After getting the initial response, you’ll need to make a separate API call to the /blocks endpoint. Use the page ID as a parameter. This will give you a more detailed response including the file URLs.
Something like:
GET https://api.notion.com/v1/blocks/{page_id}/children
The response should contain the actual file URLs. Just be aware these URLs are temporary and expire after a while. I ended up implementing a caching system to refresh the URLs periodically.
It’s not the most elegant solution, but it gets the job done. Hope this helps!
hey sophia, i ran into this too. the api doesn’t give urls directly
you gotta make another request to the page object endpoint using the block id. then parse the response for the file url. it’s a bit of a pain but works. good luck!
Unfortunately, retrieving file URLs from Notion’s API isn’t straightforward. The API doesn’t provide direct access to file URLs in the initial response. To obtain the actual file URLs, you need to perform an additional API call to the ‘retrieve block children’ endpoint using the page ID. This endpoint will return more detailed information about the files, including their URLs. It’s a multi-step process that requires parsing the response carefully. Keep in mind that file URLs from Notion are temporary and expire after a short period, so you may need to implement a system to refresh them periodically if you’re storing or using them long-term in your application.