Retrieving file URLs from Notion API's 'Files & media' property

Hey everyone!

I’ve been working with the Notion API Beta and I’m stuck on something. I’m trying to get data from a table that has a ‘Files & media’ property. The API gives me the file names, but I can’t figure out how to get the actual URLs to access these files. Here’s what the response looks like:

{
  "MediaFiles": {
    "id": "abc123",
    "type": "attachments",
    "attachments": [
      {
        "name": "project_image_001.png"
      }
    ]
  }
}

Am I missing something obvious here? How can I get the download links for these files? Any help would be awesome! Thanks in advance!

I’ve encountered this issue before when working with the Notion API. To get the actual file URLs, you’ll need to take an extra step. After retrieving the page content, look for the block ID associated with the file. Then, make a separate GET request to the /v1/blocks/{block_id} endpoint. This should return more detailed information about the file, including a temporary URL for download.

Be aware that these URLs are time-limited and will expire, typically after an hour. If you’re building an application that needs consistent access to these files, you’ll want to implement a system to refresh the URLs periodically or download and store the files on your own server for more reliable access.

It’s a bit cumbersome, but that’s currently the most straightforward way to handle file retrieval through the Notion API.

hey scarlettturner, i ran into this too! the api doesn’t give direct urls :frowning: you gotta make another request to /v1/blocks/{block_id} for each file. it’ll give you a temp url, but watch out cuz they expire fast. kinda annoying but it works. good luck with your project!

In my experience, the Notion API’s ‘Files & media’ property only returns the file names without the download URLs. You need to extract the file’s ID and then make a separate API call to the /blocks endpoint to retrieve detailed information, including the temporary URL. Keep in mind that the URLs expire quickly, so you may have to implement a caching mechanism or refresh the URLs periodically if you plan on using them later.