New API endpoint: Shared Link Metadata

// By Eric Feng • Aug 31, 2015

Today we’re announcing a much-requested API endpoint: shared link metadata, which lets you get metadata (similar to Core API’s /metadata) from Dropbox shared links. This API endpoint doesn’t require a user access token.

We’ve been working with our friends at Slack and Trello to help develop this endpoint to super-power Dropbox shared links pasted into a channel or board. We’re now looking forward to seeing how the rest of the developer community uses it.

To test this new endpoint out, you’ll need two things: a Dropbox shared link and a Dropbox app. If you’ve never created a Dropbox shared link, it only takes a few clicks. Creating a Dropbox app is just as easy.

In the following examples, I’ll be using curl and a link to a folder with 2 images inside: https://www.dropbox.com/sh/748f94925f0gesq/AAAMSoRJyhJFfkupnAU0wXuva?dl=0

Using an app key and secret

Request

curl -X POST https://api.dropbox.com/1/metadata/link -u <APP_KEY>:<APP_SECRET> \
  -d link=https://www.dropbox.com/sh/748f94925f0gesq/AAAMSoRJyhJFfkupnAU0wXuva?dl=0

Response

200 OK
 
Content-Type: application/json
{
    "bytes": 0,
    "contents": [
        {
            "bytes": 228105,
            "client_mtime": "Fri, 28 Aug 2015 18:39:12 +0000",
            "icon": "page_white_picture",
            "is_dir": false,
            "mime_type": "image/jpeg",
            "modified": "Fri, 28 Aug 2015 18:44:13 +0000",
            "path": "/Pusheen.jpg",
            "rev": "155114a7004",
            "root": "link",
            "size": "222.8 KB",
            "thumb_exists": true
        },
        {
            "bytes": 550913,
            "client_mtime": "Fri, 28 Aug 2015 18:39:58 +0000",
            "icon": "page_white_picture",
            "is_dir": false,
            "mime_type": "image/jpeg",
            "modified": "Fri, 28 Aug 2015 18:44:08 +0000",
            "path": "/Sausalito.jpg",
            "rev": "153114a7004",
            "root": "link",
            "size": "538 KB",
            "thumb_exists": true
        }
    ],
    "folder_name": "Shared Link Metadata",
    "hash": "f9433abe16be847f75ec8949b3870534",
    "icon": "folder",
    "in_dropbox": false,
    "is_dir": true,
    "link": "https://www.dropbox.com/sh/748f94925f0gesq/AAAMSoRJyhJFfkupnAU0wXuva?dl=0",
    "modified": "Fri, 10 Jul 2015 01:07:57 +0000",
    "path": null,
    "rev": "141114a7004",
    "root": "link",
    "size": "0 bytes",
    "thumb_exists": false,
    "visibility": "PUBLIC"
}

Using a user access token

If your app has an authenticated user, it's helpful to know whether a shared link points to a file in that user’s Dropbox. If you call /metadata/link with the user’s access token, the returned metadata will tell you whether the shared link points to a file or folder in that user’s Dropbox via the in_dropbox field. If in_dropbox is true, the path field will tell you the exact path to the file within the user’s Dropbox. With that path, your app can use the rest of the Core API to work directly with the file. If this is your first time creating an access token, try our OAuth guide.

Request

curl -X POST https://api.dropbox.com/1/metadata/link \
  -d link=https://www.dropbox.com/sh/748f94925f0gesq/AAAMSoRJyhJFfkupnAU0wXuva?dl=0 \
  -H "Authorization: Bearer <ACCESS_TOKEN>"

Response

200 OK
 
Content-Type: application/json
{
    "bytes": 0,
    "contents": [
        {
            "bytes": 228105,
            "client_mtime": "Fri, 28 Aug 2015 18:39:12 +0000",
            "icon": "page_white_picture",
            "is_dir": false,
            "mime_type": "image/jpeg",
            "modified": "Fri, 28 Aug 2015 18:44:13 +0000",
            "path": "/Pusheen.jpg",
            "rev": "155114a7004",
            "root": "link",
            "size": "222.8 KB",
            "thumb_exists": true
        },
        {
            "bytes": 550913,
            "client_mtime": "Fri, 28 Aug 2015 18:39:58 +0000",
            "icon": "page_white_picture",
            "is_dir": false,
            "mime_type": "image/jpeg",
            "modified": "Fri, 28 Aug 2015 18:44:08 +0000",
            "path": "/Sausalito.jpg",
            "rev": "153114a7004",
            "root": "link",
            "size": "538 KB",
            "thumb_exists": true
        }
    ],
    "folder_name": "Shared Link Metadata",
    "hash": "f9433abe16be847f75ec8949b3870534",
    "icon": "folder",
    "in_dropbox": true,
    "is_dir": true,
    "link": "https://www.dropbox.com/sh/748f94925f0gesq/AAAMSoRJyhJFfkupnAU0wXuva?dl=0",
    "modified": "Fri, 10 Jul 2015 01:07:57 +0000",
    "path": "/Blog/Shared Link Metadata",
    "rev": "141114a7004",
    "root": "dropbox",
    "size": "0 bytes",
    "thumb_exists": false,
    "visibility": "PUBLIC"
}

Examining subfolders or files

If your shared link points to a folder (like mine did) and you just need metadata for specific files or subfolders in that folder, you can pass its relative path in the path parameter:

Request

curl -X POST https://api.dropbox.com/1/metadata/link \
  -d link=https://www.dropbox.com/sh/748f94925f0gesq/AAAMSoRJyhJFfkupnAU0wXuva?dl=0 \
  -d path=/Pusheen.jpg -H "Authorization: Bearer <ACCESS_TOKEN>"

Response

200 OK
 
Content-Type: application/json
{
    "bytes": 228105,
    "client_mtime": "Fri, 28 Aug 2015 18:39:12 +0000",
    "icon": "page_white_picture",
    "in_dropbox": false,
    "is_dir": false,
    "link": "https://www.dropbox.com/sh/748f94925f0gesq/AAACxOBrrlgYrMtZ804XECFQa/Pusheen.jpg?dl=0",
    "mime_type": "image/jpeg",
    "modified": "Fri, 28 Aug 2015 18:44:13 +0000",
    "path": "/Pusheen.jpg",
    "rev": "155114a7004",
    "root": "link",
    "size": "222.8 KB",
    "thumb_exists": true,
    "visibility": "PUBLIC"
}

For full details on this new endpoint, check out our Core API docs. Happy hacking!


// Copy link