Read a media URL
Use Node.js 22 or later. You need an access token withvault:read, which lets your app read Vault media. Choose a photo’s numeric media ID from a linked account shared with that token.
Clone the Vault image example on GitHub and copy its settings template:
OFAUTH_ACCESS_TOKEN, OFAUTH_LINKED_ACCOUNT_ID, and OFAUTH_MEDIA_ID in .env, then run the example:
GET /v3/access/vault/media/{mediaId}. A successful photo response contains these fields. Other fields are omitted. The image URL below is an example:
Saved media.html for media 123456, with your actual media ID. Open media.html in a browser to see the full-size photo scaled to the window. The page contains the returned display URL, not your access token. Keep the generated file out of version control.
Use files.preview for a preview or files.thumb for a thumbnail when those fields are present. Posts, messages, and videos can return different fields. Check their API reference before using this example for them.
Refresh expired URLs
If the image stops loading, rerunnpm start with the same OFAUTH_MEDIA_ID and linked account, then reload media.html. The script reads the same Vault item and replaces the saved display URL. Save the media ID and the linked account ID so you can request a new URL later.
If the request fails, follow its recovery action. If isReady is false, wait before reading the item again. If access is denied or the item is unavailable, retrying the old URL will not fix it.