ファイルに共有リンクを追加

put
https://api.box.com/2.0
/files/:file_id

ファイルに共有リンクを追加します。

リクエスト

bearer [ACCESS_TOKEN]
application/json

パスパラメータ

stringパス内必須
12345

ファイルを表す一意の識別子。

ファイルIDを確認するには、ウェブアプリケーションでファイルにアクセスして、URLからIDをコピーします。たとえば、URLがhttps://*.app.box.com/files/123の場合、file_id123です。

クエリパラメータ

stringクエリ内必須
shared_link

この項目に返されるshared_linkフィールドを明示的にリクエストします。

リクエスト本文

レスポンス

application/jsonファイル (Full)

新しい共有リンクが追加されているファイルのBase版の表示を返します。

権限の組み合わせが正しくない場合に返されます。

Authorizationヘッダーで指定されているアクセストークンが認識されないか、指定されていない場合に返されます。

更新を完了するための権限がユーザーに不足している場合に返されます。

ファイルが見つからない場合、またはユーザーにファイルへのアクセス権限が与えられていない場合に返されます。

file_idが認識されていない形式で指定されている場合に返されます。

If-Matchヘッダーがファイルの現在のetag値と一致しない場合にエラーを返します。これは、ファイルが前回リクエストされたときから変更されていることを示します。

予期しないクライアントエラー。

put
ファイルに共有リンクを追加
このドキュメント内で一部のAPIを試せるようになりました。
ログイン

リクエストの例

cURL
curl -i -X PUT "https://api.box.com/2.0/files/32423234?fields=shared_link" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -d '{
       "shared_link": {
         "access": "open",
         "password": "mypassword",
         "unshared_at": "2012-12-12T10:53:43-08:00",
         "permissions": {
           "can_download": false
         }
       }
     }'
.NET
string fileId = "11111";
var sharedLinkParams = new BoxSharedLinkRequest()
{
    Access = BoxSharedLinkAccessType.open,
    Permissions = new BoxPermissionsRequest
    {
        Download = true,
        Edit = true
    }
};
BoxFile file = client.FilesManager.CreateSharedLinkAsync(fileId, sharedLinkParams);
string sharedLinkUrl = file.SharedLink.Url;
Java
// Optionally we can calculate and set the date when shared link will automatically be disabled
final long ONE_WEEK_MILLIS = 1000 * 60 * 60 * 24 * 7;
long unsharedTimestamp = System.currentTimeMillis() + ONE_WEEK_MILLIS;
Date unsharedDate = new Date(unsharedTimestamp);

BoxFile file = new BoxFile(api, "id");
BoxSharedLinkRequest sharedLinkRequest = new BoxSharedLinkRequest()
    .access(OPEN)
    .permissions(true, true)
    .unsharedDate(unsharedDate);
BoxSharedLink sharedLink = file.createSharedLink(sharedLinkRequest);
Python
file_id = '11111'

url = client.file(file_id).get_shared_link(access='open', allow_download=True, allow_edit=True)
print(f'The file shared link URL is: {url}')
Node
client.files.update('12345', {
  shared_link: {
    access: "open",
    password: "do-not-use-this-password", 
    unshared_at: "2022-12-12T10:53:43-08:00",
    vanity_name: "my-shared-link",
    permissions: {
	  can_view: true,
	  can_download: true,
	  can_edit: true
    }
  }
}).then(file => {
  // ...
})
iOS
client.files.setSharedLink(
    forFile: "11111", 
    access: .open, 
    canDownload: true, 
    canEdit: true
) { (result: Result<SharedLink, BoxSDKError>) in
    guard case let .success(sharedLink) = result else {
        print("Error setting file shared link")
        return
    }

    print("File shared link URL is \(sharedLink.url), with \(sharedLink.access) access")
}

レスポンスの例

{
  "id": "12345",
  "type": "file",
  "etag": "1",
  "shared_link": {
    "url": "https://app.box.com/s/kwio6b4ovt1264rnfbyqo1",
    "download_url": "https://app.box.com/shared/static/kwio6b4ovt1264rnfbyqo1.pdf",
    "vanity_url": null,
    "vanity_name": null,
    "effective_access": "open",
    "effective_permission": "can_download",
    "is_password_enabled": false,
    "unshared_at": "2020-09-21T10:34:41-07:00",
    "download_count": 0,
    "preview_count": 0,
    "access": "open",
    "permissions": {
      "can_preview": true,
      "can_download": true,
      "can_edit": true
    }
  }
}