GraphApi.Files (GraphApi v1.0.0-rc.1)

Copy Markdown View Source

Operations on OneDrive/SharePoint files (/drives, /drive/items, etc.).

Examples

{:ok, drive} = GraphApi.Files.get_drive("user-id")
{:ok, %{"value" => items}} = GraphApi.Files.list_root_children("drive-id")
{:ok, content} = GraphApi.Files.download_content("drive-id", "item-id")

Summary

Functions

Invites recipients and adds permissions to a drive item.

Copies a drive item to a new location. Returns 202 Accepted with an async monitor URL.

Creates a new folder under the given parent item.

Creates a sharing link for a drive item.

Creates an upload session for large file uploads (> 4 MB).

Deletes a permission from a drive item.

Downloads the content of a drive item.

Delta query for a drive's root folder. Returns file/folder changes since the last sync.

Gets a user's default drive.

Gets a drive item by ID.

Gets a shared drive item by its sharing token or encoded sharing URL.

Gets a special folder (e.g., "documents", "photos", "approot") in a drive.

Lists children of a specific item in a drive.

Lists all drives available to a user.

Lists permissions on a drive item.

Lists children of the root folder in a drive.

Lists thumbnails for a drive item.

Lists versions of a drive item.

Searches for items in a drive matching the given query string.

Updates a drive item's metadata (name, description, etc.).

Uploads a small file (up to 4 MB) to a drive.

Functions

add_permission(drive_id, item_id, attrs, opts \\ [])

@spec add_permission(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Invites recipients and adds permissions to a drive item.

add_permission_query(drive_id, item_id, attrs, opts \\ [])

@spec add_permission_query(String.t(), String.t(), map(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of add_permission/4.

copy_item(drive_id, item_id, attrs, opts \\ [])

@spec copy_item(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Copies a drive item to a new location. Returns 202 Accepted with an async monitor URL.

copy_item_query(drive_id, item_id, attrs, opts \\ [])

@spec copy_item_query(String.t(), String.t(), map(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of copy_item/4.

create_folder(drive_id, parent_item_id, attrs, opts \\ [])

@spec create_folder(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Creates a new folder under the given parent item.

create_folder_query(drive_id, parent_item_id, attrs, opts \\ [])

@spec create_folder_query(String.t(), String.t(), map(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of create_folder/4.

create_sharing_link(drive_id, item_id, attrs, opts \\ [])

@spec create_sharing_link(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Creates a sharing link for a drive item.

create_upload_session(drive_id, path, attrs \\ %{}, opts \\ [])

@spec create_upload_session(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Creates an upload session for large file uploads (> 4 MB).

Returns the upload URL to use for uploading file chunks.

create_upload_session_query(drive_id, path, attrs \\ %{}, opts \\ [])

@spec create_upload_session_query(String.t(), String.t(), map(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of create_upload_session/4.

delete_item(drive_id, item_id, opts \\ [])

@spec delete_item(String.t(), String.t(), keyword()) :: :ok | {:error, term()}

Deletes a drive item.

delete_item_query(drive_id, item_id, opts \\ [])

@spec delete_item_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of delete_item/3.

delete_permission(drive_id, item_id, perm_id, opts \\ [])

@spec delete_permission(String.t(), String.t(), String.t(), keyword()) ::
  :ok | {:error, term()}

Deletes a permission from a drive item.

delete_permission_query(drive_id, item_id, perm_id, opts \\ [])

@spec delete_permission_query(String.t(), String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of delete_permission/4.

download_content(drive_id, item_id, opts \\ [])

@spec download_content(String.t(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Downloads the content of a drive item.

Returns {:ok, binary} with the raw file content.

download_content_query(drive_id, item_id, opts \\ [])

@spec download_content_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of download_content/3.

drive_delta(drive_id, opts \\ [])

@spec drive_delta(
  String.t(),
  keyword()
) :: {:ok, GraphApi.Delta.delta_page()} | {:error, term()}

Delta query for a drive's root folder. Returns file/folder changes since the last sync.

drive_delta_query(drive_id, opts \\ [])

@spec drive_delta_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()

Batch query variant of drive_delta/2.

get_drive(user_id, opts \\ [])

@spec get_drive(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Gets a user's default drive.

get_drive_query(user_id, opts \\ [])

@spec get_drive_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()

Batch query variant of get_drive/2.

get_item(drive_id, item_id, opts \\ [])

@spec get_item(String.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}

Gets a drive item by ID.

get_item_by_path(drive_id, path, opts \\ [])

@spec get_item_by_path(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Gets a drive item by path.

The path should be relative to the root (e.g., "Documents/report.docx").

get_item_by_path_query(drive_id, path, opts \\ [])

@spec get_item_by_path_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of get_item_by_path/3.

get_item_query(drive_id, item_id, opts \\ [])

@spec get_item_query(String.t(), String.t(), keyword()) :: GraphApi.Batch.Request.t()

Batch query variant of get_item/3.

get_shared_item(share_id, opts \\ [])

@spec get_shared_item(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Gets a shared drive item by its sharing token or encoded sharing URL.

get_shared_item_query(share_id, opts \\ [])

@spec get_shared_item_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()

Batch query variant of get_shared_item/2.

get_special_folder(drive_id, name, opts \\ [])

@spec get_special_folder(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Gets a special folder (e.g., "documents", "photos", "approot") in a drive.

get_special_folder_query(drive_id, name, opts \\ [])

@spec get_special_folder_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of get_special_folder/3.

list_children(drive_id, item_id, opts \\ [])

@spec list_children(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Lists children of a specific item in a drive.

list_children_query(drive_id, item_id, opts \\ [])

@spec list_children_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of list_children/3.

list_drives(user_id, opts \\ [])

@spec list_drives(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Lists all drives available to a user.

list_drives_query(user_id, opts \\ [])

@spec list_drives_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()

Batch query variant of list_drives/2.

list_permissions(drive_id, item_id, opts \\ [])

@spec list_permissions(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Lists permissions on a drive item.

list_permissions_query(drive_id, item_id, opts \\ [])

@spec list_permissions_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of list_permissions/3.

list_root_children(drive_id, opts \\ [])

@spec list_root_children(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Lists children of the root folder in a drive.

list_root_children_query(drive_id, opts \\ [])

@spec list_root_children_query(
  String.t(),
  keyword()
) :: GraphApi.Batch.Request.t()

Batch query variant of list_root_children/2.

list_thumbnails(drive_id, item_id, opts \\ [])

@spec list_thumbnails(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Lists thumbnails for a drive item.

list_thumbnails_query(drive_id, item_id, opts \\ [])

@spec list_thumbnails_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of list_thumbnails/3.

list_versions(drive_id, item_id, opts \\ [])

@spec list_versions(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Lists versions of a drive item.

list_versions_query(drive_id, item_id, opts \\ [])

@spec list_versions_query(String.t(), String.t(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of list_versions/3.

search(drive_id, query, opts \\ [])

@spec search(String.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}

Searches for items in a drive matching the given query string.

search_query(drive_id, query, opts \\ [])

@spec search_query(String.t(), String.t(), keyword()) :: GraphApi.Batch.Request.t()

Batch query variant of search/3.

update_item(drive_id, item_id, attrs, opts \\ [])

@spec update_item(String.t(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, term()}

Updates a drive item's metadata (name, description, etc.).

update_item_query(drive_id, item_id, attrs, opts \\ [])

@spec update_item_query(String.t(), String.t(), map(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of update_item/4.

upload_small(drive_id, path, content, opts \\ [])

@spec upload_small(String.t(), String.t(), binary(), keyword()) ::
  {:ok, map()} | {:error, term()}

Uploads a small file (up to 4 MB) to a drive.

For larger files, use create_upload_session/4.

upload_small_query(drive_id, path, content, opts \\ [])

@spec upload_small_query(String.t(), String.t(), binary(), keyword()) ::
  GraphApi.Batch.Request.t()

Batch query variant of upload_small/4.