client.files
この名前空間のすべてのメソッドの、シグネチャ、パラメーター、戻り値、例。
メソッド
Every attachment the mailbox holds, sent and received, and the files uploaded to it, with their bytes, the download links they went out as and whether each can be deleted.
files.list
List one page of the files the mailbox holds
list(q: nil, kind: nil, direction: nil, address: nil, since: nil, until: nil, sort: nil, limit: nil, cursor: nil, api_key: nil) -> OpenEmail::PageReturns one page of the Files page: every attachment the mailbox holds, sent and received, and every file uploaded to it, with its name, type, size, the address it came to, the thread it belongs to and whether it can be deleted. list_all collects every page and iterate walks them lazily.
Only an upload that nothing depends on can be deleted, and its deletable is true. Every other row has a usage saying what keeps it: received, sent, linked for an upload that went out as a download link that still works, or scheduled for one attached to a message that has not gone out yet.
A key limited to particular addresses or domains sees only the files that arrived at them, the same boundary the thread list uses, so it does not see files uploaded for the whole workspace. A deleted file is not listed.
The index starts from the day it shipped, so an older mailbox lists what has arrived since. Older attachments are still on their messages, where threads.list_attachments reads them.
パラメーター
qStringSearches the file name and its type. Words match loosely, and a close spelling is tried when nothing matches exactly.
kindStringKeeps one kind:
image,pdf,audio,videoortext, the choices of the filter on the Files page.directionStringKeeps one direction:
inboundfor files that arrived on a message,outboundfor files that went out on one,uploadedfor files put on the Files page.addressStringKeeps the files of one address, the
deliveredToof the file, compared without regard to case.sinceTime, Date or StringKeeps files added at or after this moment. A
Timeor an ISO 8601 String.untilTime, Date or StringKeeps files added before this moment. A
Timeor an ISO 8601 String.sortStringnewest(the default),oldest,largestorname. A cursor carries on in the order it was handed out in.limitIntegerPage size, from 1 to 100. The server defaults to 25.
cursorStringThe
next_cursorof the previous page. Leave it out for the first page.api_keyStringOverrides the client API key for this call only.
戻り値
An OpenEmail::Page of Hashes, with items, has_more? and next_cursor. Each item has id, filename, mimeType, sizeBytes, direction, threadId, messageId, deliveredTo, usage, deletable and createdAt.
例
page = client.files.list(kind: "pdf", sort: "largest") p page.items.map { |file| [file[:filename], file[:sizeBytes]] }注意事項
Needs
files:read. Reading an email withthreads:readstill reads the attachments on it;files:readreads every file, uploads included.The cursor is opaque and holds where the last row sat in this order. A cursor this list did not hand out, or one handed out under another
sort:, is a 400invalid_cursor.
ほかの提供先
- API
GET /files- TypeScript
files.list()- Python
files.list()- CLI
openemail files list
files.list_all
Collect every file into one array
list_all(q: nil, kind: nil, direction: nil, address: nil, since: nil, until: nil, sort: nil, limit: nil, cursor: nil, api_key: nil) -> Array<Hash>Walks every page of list and returns every file in one Array, in the order sort: names. One request per page, with the same filters on each.
パラメーター
qStringSearches the file name and its type. Words match loosely, and a close spelling is tried when nothing matches exactly.
kindStringKeeps one kind:
image,pdf,audio,videoortext, the choices of the filter on the Files page.directionStringKeeps one direction:
inboundfor files that arrived on a message,outboundfor files that went out on one,uploadedfor files put on the Files page.addressStringKeeps the files of one address, the
deliveredToof the file, compared without regard to case.sinceTime, Date or StringKeeps files added at or after this moment. A
Timeor an ISO 8601 String.untilTime, Date or StringKeeps files added before this moment. A
Timeor an ISO 8601 String.sortStringnewest(the default),oldest,largestorname. A cursor carries on in the order it was handed out in.limitIntegerPage size for each request, from 1 to 100. The server defaults to 25.
cursorStringStarts the walk after this cursor instead of the first page.
api_keyStringOverrides the client API key for every page of this walk.
戻り値
An Array of Hashes holding every file, each with the fields list returns.
例
all = client.files.list_all(q: "invoice") puts all.size注意事項
If any page fails, the error is raised and the rows already fetched are discarded.
ほかの提供先
- API
GET /files- TypeScript
files.listAll()- Python
files.list_all()
files.iterate
Stream the files one at a time
iterate(q: nil, kind: nil, direction: nil, address: nil, since: nil, until: nil, sort: nil, limit: nil, cursor: nil, api_key: nil, &block) -> Enumerator<Hash>Returns an Enumerator that yields one file at a time, in the order sort: names, and requests the next page only once the current one is drained. Nothing is fetched until you consume it, and breaking out of the loop stops the requests. Given a block, it yields each file to the block instead.
パラメーター
qStringSearches the file name and its type. Words match loosely, and a close spelling is tried when nothing matches exactly.
kindStringKeeps one kind:
image,pdf,audio,videoortext, the choices of the filter on the Files page.directionStringKeeps one direction:
inboundfor files that arrived on a message,outboundfor files that went out on one,uploadedfor files put on the Files page.addressStringKeeps the files of one address, the
deliveredToof the file, compared without regard to case.sinceTime, Date or StringKeeps files added at or after this moment. A
Timeor an ISO 8601 String.untilTime, Date or StringKeeps files added before this moment. A
Timeor an ISO 8601 String.sortStringnewest(the default),oldest,largestorname. A cursor carries on in the order it was handed out in.limitIntegerPage size for each request, from 1 to 100. The server defaults to 25.
cursorStringStarts the walk after this cursor instead of the first page.
api_keyStringOverrides the client API key for every page of this walk.
戻り値
An Enumerator of Hashes, one file per step (or yields each one to a block).
例
client.files.iterate(sort: "oldest") do |file| puts "#{file[:createdAt]} #{file[:filename]}"end注意事項
Pages are fetched only as they are needed, so an abandoned loop costs only the pages you consumed.
ほかの提供先
- API
GET /files- TypeScript
files.iterate()- Python
files.iterate()
files.get
Read one file by id
get(id, api_key: nil) -> HashReturns one file: its name, type, size, whether it was sent, received or uploaded, the address it came to, the thread and message it belongs to, and whether it can be deleted. download fetches its bytes.
deletable is true only for an upload that nothing depends on. Otherwise usage says what keeps it: received or sent for a file that came in or went out on a message, linked for an upload that went out as a download link that still works, and scheduled for one attached to a message that has not gone out yet.
パラメーター
idString必須The id from
list,file_and 24 hex.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash with the fields list returns for each file, usage and deletable included.
例
file = client.files.get("file_6bb640f5b99e47deb758f1f5") puts file[:filename], file[:mimeType]注意事項
A deleted file, one outside the addresses a narrowed key holds, and an unknown id all answer 404
resource_not_found.
ほかの提供先
- API
GET /files/{id}- TypeScript
files.get()- Python
files.get()- CLI
openemail files get
files.stats
Count the files and the space they take
stats(api_key: nil) -> HashReturns the numbers on the Analytics tab of the Files page in one request: how many files the mailbox holds and how many bytes they take, in all and split into received, sent and uploaded, the file types and the addresses taking the most space, how many files arrived on each of the last 30 days, and the download links still working with how often they were fetched.
Deleted files are not counted. A key limited to particular addresses or domains counts only the files that arrived at them, so files uploaded for the whole workspace are left out of its numbers.
パラメーター
api_keyStringOverrides the client API key for this call only.
戻り値
A Hash with totals, received, sent and uploaded, each a Hash of files and bytes, then types, byDay, addresses and links.
例
stats = client.files.stats puts "#{stats[:totals][:files]} files in #{stats[:totals][:bytes]} bytes, #{stats[:uploaded][:files]} of them uploaded"p stats[:types].map { |type| [type[:mimeType], type[:bytes]] }注意事項
Needs
files:read.typesholds at most the 8 types taking the most bytes andaddressesat most the 6 addresses holding the most. A file uploaded for the whole workspace has no address, so it counts in the totals and never inaddresses.byDaycovers the last 30 days in UTC, today included, and is sparse: a day on which no file arrived has no entry, so a chart must fill the gaps. EachdayisYYYY-MM-DD.linkscounts the download links that still work:sharesof them, fetcheddownloadstimes in all, last atlastDownloadAt, which is nil when none was ever fetched. Scanners and link previewers are left out of the count.
ほかの提供先
- API
GET /files/stats- TypeScript
files.stats()- Python
files.stats()- CLI
openemail files stats
files.download
Fetch the bytes of a file
download(id, api_key: nil) -> StringReturns the file exactly as it is stored, the same bytes the Download action on the Files page saves. The response carries the file's own Content-Type and name.
パラメーター
idString必須The id from
list.api_keyStringOverrides the client API key for this call only.
戻り値
A binary String holding the file.
例
file = client.files.get("file_6bb640f5b99e47deb758f1f5")bytes = client.files.download(file[:id]) File.binwrite(file[:filename], bytes)注意事項
The whole file is held in memory, so fetch very large ones one at a time.
A file whose bytes are gone from storage answers 404 like a missing one.
ほかの提供先
- API
GET /files/{id}/content- TypeScript
files.download()- Python
files.download()- CLI
openemail files download
files.list_links
List the download links a file went out as
list_links(id, limit: nil, cursor: nil, api_key: nil) -> OpenEmail::PageReturns one page of the download links made for this file, newest first. A large attachment sent from OpenEmail travels as a link rather than inside the message, and each send makes a link of its own. Every row says how often it was fetched, when last, and whether it was revoked. While one of its links still works, an upload cannot be deleted.
A file attached inside a message has no links, because nothing records when those are opened.
パラメーター
idString必須The file id from
list.limitIntegerPage size, from 1 to 100. The server defaults to 25.
cursorStringThe
next_cursorof the previous page. Leave it out for the first page.api_keyStringOverrides the client API key for this call only.
戻り値
An OpenEmail::Page of Hashes, with items, has_more? and next_cursor. Each item has id, url, host, downloads, lastDownloadAt, revokedAt and createdAt.
例
page = client.files.list_links("file_6bb640f5b99e47deb758f1f5") p page.items.map { |link| [link[:url], link[:downloads]] }注意事項
The count leaves out scanners and link previewers, the same classifier the
email.downloadedwebhook uses.
ほかの提供先
- API
GET /files/{id}/links- TypeScript
files.listLinks()- Python
files.list_links()- CLI
openemail files list-links
files.list_all_links
Collect every download link of a file into one array
list_all_links(id, limit: nil, cursor: nil, api_key: nil) -> Array<Hash>Walks every page of list_links and returns every download link of the file in one Array, newest first. One request per page, with the same filters on each.
パラメーター
idString必須The file id from
list.limitIntegerPage size for each request, from 1 to 100. The server defaults to 25.
cursorStringStarts the walk after this cursor instead of the first page.
api_keyStringOverrides the client API key for every page of this walk.
戻り値
An Array of Hashes holding every download link of the file, each with the fields list_links returns.
例
links = client.files.list_all_links("file_6bb640f5b99e47deb758f1f5") fetched = links.sum { |link| link[:downloads] } puts fetched注意事項
If any page fails, the error is raised and the rows already fetched are discarded.
ほかの提供先
- API
GET /files/{id}/links- TypeScript
files.listAllLinks()- Python
files.list_all_links()
files.iterate_links
Stream the download links of a file one at a time
iterate_links(id, limit: nil, cursor: nil, api_key: nil, &block) -> Enumerator<Hash>Returns an Enumerator that yields one link at a time, newest first, and requests the next page only once the current one is drained. Nothing is fetched until you consume it, and breaking out of the loop stops the requests. Given a block, it yields each link to the block instead.
パラメーター
idString必須The file id from
list.limitIntegerPage size for each request, from 1 to 100. The server defaults to 25.
cursorStringStarts the walk after this cursor instead of the first page.
api_keyStringOverrides the client API key for every page of this walk.
戻り値
An Enumerator of Hashes, one link per step (or yields each one to a block).
例
client.files.iterate_links("file_6bb640f5b99e47deb758f1f5") do |link| puts "#{link[:url]} #{link[:revokedAt]}"end注意事項
Pages are fetched only as they are needed, so an abandoned loop costs only the pages you consumed.
ほかの提供先
- API
GET /files/{id}/links- TypeScript
files.iterateLinks()- Python
files.iterate_links()
files.create_link
Publish a file at a public link
create_link(id, domain: nil, api_key: nil) -> HashMakes a public download link for the file and returns it. Anybody holding url can open the file without signing in, which is how an image or a document is referenced from an email or a web page. Each call makes a new link with its own download count, and a link keeps working until it is revoked with revoke_link or the file is deleted.
The link lives on the files host of domain: when that domain has one set up, such as files.acme.com, else on the files host of the address the file belongs to, else on the OpenEmail API address. A file that came in or went out on a message is copied to public storage first. Programs and scripts are refused with 422 file_unshareable.
パラメーター
idString必須The file id from
list.domainStringThe domain whose files host serves the link, such as
acme.com.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash with id, url, host, downloads, lastDownloadAt, revokedAt and createdAt.
例
link = client.files.create_link("file_6bb640f5b99e47deb758f1f5", domain: "acme.com") puts link[:url]注意事項
Needs
files:write.Not retried after a lost response, because a second call makes a second link. Look for it with
list_linksfirst.
ほかの提供先
- API
POST /files/{id}/links- TypeScript
files.createLink()- Python
files.create_link()- CLI
openemail files create-link
files.revoke_link
Revoke a public link
revoke_link(id, link_id, api_key: nil) -> HashStops a public link from working, for good, including in mail that already went out with it, and returns the link, revokedAt set. Revoking a link that is already revoked returns it unchanged, so the call is safe to repeat. An unknown link is a 404.
パラメーター
idString必須The file id from
list.link_idString必須The link id from
list_linksorcreate_link.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash for the link, with revokedAt set.
例
client.files.revoke_link("file_6bb640f5b99e47deb758f1f5", "shr_2f9c4a1e7b3d")注意事項
Needs
files:write.
ほかの提供先
files.revoke_all_links
Revoke every link to a file
revoke_all_links(id, api_key: nil) -> HashMakes the file private, as Make private on the Files page does: every public download link to it stops working at once, including the ones in mail that already went out. Returns revoked, how many links were still working. The file itself stays, and create_link can publish it again at a new link.
A key limited to particular addresses reaches only the files that arrived at them, and any other file is a 404.
パラメーター
idString必須The file id from
list.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash with fileId and revoked, the number of links that stopped working.
例
revoked = client.files.revoke_all_links("file_6bb640f5b99e47deb758f1f5")[:revoked] puts "#{revoked} links stopped working"注意事項
A file with no working links returns
revoked: 0, so the call is safe to repeat.Needs
files:write.
ほかの提供先
files.upload
Upload a file to the Files page
upload(data, filename: nil, content_type: nil, timeout: nil, api_key: nil) -> HashStores the bytes as a new file, the way the Upload button on the Files page does, and returns it: direction is uploaded, usage is nil and deletable is true. Attach it to a send as {fileId: file[:id]} in the attachments of emails.send, which is how a file larger than the inline cap goes out.
data is a binary String (File.binread), an IO or a Pathname, sent as the request body. The name travels as the filename query parameter, and it is cleaned rather than refused: characters a file name cannot hold become _, and a name longer than 255 characters is cut, keeping its extension. Left out, filename: falls back to an upload's original_filename or the file's own name, so only plain bytes need it. The type is content_type:, or an upload's own content_type when that is left out, then the type the file's extension names, and application/octet-stream without any of them. A value that is not shaped like a MIME type is stored as application/octet-stream too.
A key limited to particular addresses or domains uploads to the first address it holds, which becomes deliveredTo. An unlimited key uploads for the whole workspace and deliveredTo is nil, so a narrowed key never reaches that file afterwards.
パラメーター
dataString, IO or Pathname必須The file, as a binary String, an IO or a Pathname, not empty and at most 100 MB.
filenameStringThe name the file is stored and downloaded under, such as
report.pdf. Left out, it is an upload'soriginal_filenameor the file's own name, so it is needed only for plain bytes. A missing or blank name raises anArgumentErrorbefore anything is sent.content_typeStringThe MIME type, such as
application/pdf. Left out, an upload's owncontent_typeis used, else the type the file's extension names, elseapplication/octet-stream.timeoutNumericHow long the upload may take, in seconds. Left out, it is 600 seconds (10 minutes), or the client
timeoutwhen that is longer.0waits as long as it takes.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash for the new file, with direction: "uploaded", usage: nil and deletable: true.
例
file = client.files.upload(File.binread("report.pdf"), filename: "report.pdf", content_type: "application/pdf") client.emails.send( from: "[email protected]", to: "[email protected]", subject: "Your report", text: "The report is attached.", attachments: [{fileId: file[:id]}])注意事項
Needs
files:write, the same scope that deletes files.The SDK does not retry an upload, because a second attempt after a lost response could store the file twice. Look for it with
listbefore trying again.An empty file is a 400
upload_empty, a program or script, judged by its name, is a 400upload_dangerous, and a file over 100 MB is a 413upload_too_large. A key limited to addresses that holds none is a 403upload_no_address.A workspace keeps up to 10 GB of uploads, and past that a 507
upload_storage_fullholds until some are deleted. It takes 500 uploads an hour, deleted ones included, and more is a 429upload_rate_limited. A 502upload_failedmeans storage failed and nothing was kept, so it is safe to try again.
ほかの提供先
- API
POST /files- TypeScript
files.upload()- Python
files.upload()- CLI
openemail files upload
files.delete
Delete an uploaded file for good
delete(id, api_key: nil) -> HashRemoves an uploaded file: its bytes are deleted from storage and it leaves the Files page. The row stays, marked deleted, so the index knows the file existed. There is no undo.
Only an upload that nothing depends on can be deleted, the files whose deletable is true. A file that was received or sent stays with its message, and so does an upload that went out as a download link that still works or is attached to a message that has not gone out yet. Those are refused with 409 file_in_use, and the message names the file and says why. An upload that was sent inside a message can still be deleted, because the message keeps its own copy, which is listed as a separate sent file.
delete_many deletes up to 100 in one call and reports the ones it kept instead of failing.
パラメーター
idString必須The id from
list.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash with object set to file, the id, and deleted set to true.
例
begin removed = client.files.delete("file_6bb640f5b99e47deb758f1f5") puts removed[:deleted]rescue OpenEmail::ApiError => error raise unless error.code == "file_in_use" puts error.messageend注意事項
Needs
files:write, the same scope that uploads. A key limited to some addresses may delete only files that arrived at them, so an upload made for the whole workspace answers it 404.A file that is unknown, already deleted or out of reach answers 404
resource_not_found. A file in use answers 409file_in_usewithparam: "id", and itsusageongetsays which rule keeps it.The SDK does not retry a delete. A 404 on your own second attempt after a lost response means the first one worked.
ほかの提供先
- API
DELETE /files/{id}- TypeScript
files.delete()- Python
files.delete()- CLI
openemail files delete
files.delete_many
Delete up to 100 files in one call
delete_many(ids, api_key: nil) -> HashDeletes every file in ids that can be deleted, the way delete deletes one, and reports the rest instead of failing. It is what selecting several files on the Files page and pressing Delete does.
Only an uploaded file that nothing depends on can be deleted. A file that was received or sent stays with its message, and so does an upload that went out as a download link that still works or is attached to a message that has not gone out yet. Each of those comes back in kept with its usage and a reason in plain words. An id that is unknown, already deleted or outside the addresses a narrowed key holds comes back in missing. The rule is checked again at the moment of deleting, so a file that became used in between is kept.
There is no undo.
パラメーター
idsArray<String>必須1 to 100 file ids from
list. More than 100, or none, is a 422 onids. A repeated id counts once.api_keyStringOverrides the client API key for this call only.
戻り値
A Hash with object set to file_batch_delete, deleted, kept and missing. deleted and missing hold ids, and each entry of kept is a Hash with id, filename, usage and reason.
例
result = client.files.delete_many(["file_6bb640f5b99e47deb758f1f5", "file_0c3e2a91d4b7f6058e1a2b3c"]) puts "#{result[:deleted].size} deleted" result[:kept].each { |file| puts "#{file[:filename]} #{file[:reason]}" }注意事項
Needs
files:write, the same scope that uploads.A partial result returns normally rather than raising, so read
keptandmissingto see what stayed.The SDK does not retry it. Calling it again after a lost response reports the files the first call deleted in
missing.To clear out every upload that can go, keep the rows of
list_allwhosedeletableis true and pass their ids 100 at a time.
ほかの提供先
- API
POST /files/batch-delete- TypeScript
files.deleteMany()- Python
files.delete_many()- CLI
openemail files delete-many