# IRPCWOPIOperations.CreateWOPIUserSession

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Server integration API](https://developer.m-files.com/APIs/gRPC-API/integration/index.md) > [WOPI operations](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperations/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperations/CreateWOPIUserSession/

Badges: `Server integration API / specialized` `internal: not for applications` `write` `session`

Creates a WOPI user session for one file version and returns its token (or a one-time token that
can be exchanged for it).

- **Service:** [WOPI operations](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperations/index.md) `MFiles.IRPCWOPIOperations`
- **gRPC method:** `/MFiles.IRPCWOPIOperations/CreateWOPIUserSession`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/create-wopiuser-session`
- **Request:** [`CreateWOPIUserSessionRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperations/CreateWOPIUserSession/index.md#request)
- **Response:** [`CreateWOPIUserSessionResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperations/CreateWOPIUserSession/index.md#response)
- **Book and level:** Server integration API, specialized
- **Kind:** write
- **Session:** Required: the session ID from LogIn in the mfiles-session-id-bin metadata.
- **Idempotent:** no
- **Returns metadata structure version:** no
- **Streaming:** none (unary)

<a id="remarks"></a>

## Remarks

**For M-Files components only.** M-Files Web and M-Files Desktop call it before they open a file
in Office for the web. Applications should not call it.
- Requires a vault session. The caller needs read access to the object; for co-authoring of a
  checked-out object, also edit access.
- Creates an internal shared link for the file (`SHARED_LINK_TYPE_WOPIREADONLY`,
  `SHARED_LINK_TYPE_WOPIEDIT` or `SHARED_LINK_TYPE_CO_AUTHORING` by `action_type`; co-authoring
  reuses an existing co-authoring link) and a WOPI user session that refers to it.
- The WOPI user session expires 30 minutes after it was created or last used (the default; the
  server administrator can change it). A one-time token expires after 5 minutes and can be
  exchanged only once, with
  [GetWOPIUserSessionKey](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperationsPublic/GetWOPIUserSessionKey/index.md).
- For `WOPIACTION_TYPE_VIEW` of a checked-out object, the latest checked-in version is shared; an
  object that has never been checked in fails with access denied.

<a id="request"></a>

## Request: CreateWOPIUserSessionRequest

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `wopi_user_session` | [`WOPIUserSession`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.WOPIUserSession/index.md) | The file to open: `obj_ver`, `file_ver`, `action_type`, `user_account_id` (the session's own user ID), `external_username` (usually empty) and `additional_data` (the URLs and culture that the WOPI host passes on to Office for the web; the URLs are validated). The other fields are ignored. |
| `wopi_user_session.wopi_user_session_key` | `string` | The WOPI vault user session key. |
| `wopi_user_session.wopi_accesskey` | `string` | The access of the shared file. |
| `wopi_user_session.action_type` | [`WOPIActionType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.WOPIActionType/index.md) | The WOPI Action type. Values: `WOPIACTION_TYPE_VIEW` (0), `WOPIACTION_TYPE_EDIT` (1), `WOPIACTION_TYPE_COAUTHORING` (2). |
| `wopi_user_session.user_account_id` | `uint32` | The user ID. |
| `wopi_user_session.user_account_name` | `string` | The user Account Name. |
| `wopi_user_session.external_username` | `string` | The External user name. |
| `wopi_user_session.additional_data` | [`WOPIClientAdditionalData`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.WOPIClientAdditionalData/index.md) | WOPI Client Additional data. |
| `wopi_user_session.additional_data.return_uri` | `string` | The Return URL. |
| `wopi_user_session.additional_data.main_app_url` | `string` | The Main Appp URL. |
| `wopi_user_session.additional_data.wopi_end_point` | `string` | The WOPI Endpoint. |
| `wopi_user_session.additional_data.culture_identifier` | `string` | The Culture identifier. |
| `wopi_user_session.additional_data.action_url` | `string` | The action URL. |
| `wopi_user_session.additional_data.host_edit_url` | `string` | The Host edit URL. |
| `wopi_user_session.obj_ver` | [`ObjVer`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVer/index.md) | The ObjVer of the object. |
| `wopi_user_session.obj_ver.obj_id` | [`ObjID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjID/index.md) | The object. |
| `wopi_user_session.obj_ver.version` | [`ObjVerVersion`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.ObjVerVersion/index.md) | The version. Usually `OBJ_VER_VERSION_TYPE_SPECIFIC` with `internal_version`. |
| `wopi_user_session.file_ver` | [`FileVer`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.FileVer/index.md) | The FileVer of the object. |
| `wopi_user_session.file_ver.file_id` | [`FileID`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.FileID/index.md) | The file. |
| `wopi_user_session.file_ver.type` | [`FileVerType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.FileVerType/index.md) | `FILE_VER_TYPE_SPECIFIC` for a file version number. Values: `FILE_VER_TYPE_UNINITIALIZED` (0), `FILE_VER_TYPE_LATEST` (1), `FILE_VER_TYPE_ANY` (2), `FILE_VER_TYPE_SPECIFIC` (3). |
| `wopi_user_session.file_ver.internal_version` | `int32` | The file version number. |
| `wopi_user_session.file_ver.external_repository_version` | `string` | Used only for files in external repositories. Leave empty. |
| `wopi_user_session.file_ver.external_repository_sort_key` | `int64` | Used only for files in external repositories. Leave 0. |
| `wopi_user_session.is_shared_file` | `bool` | Specifies the Shared file. |
| `wopi_user_session.is_coauthor` | `bool` | Specifies the Co-authored file. |
| `wopi_user_session.csrftoken` | `string` | The CSRF Token. |
| `wopi_user_session.onetimetoken` | `string` | The One Time Token. |
| `wopi_user_session.is_edit_allowed` | `bool` | Specifies whether the file can be edited or not. |
| `wopi_user_session.client_type` | [`ClientType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.ClientType/index.md) | The client type (user agent) identifier. |
| `type` | [`WOPITokenType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.WOPITokenType/index.md) | `WOPITOKEN_TYPE_WOPIVAULT_USER_SESSION_TOKEN` (the default) returns the session token itself; `WOPITOKEN_TYPE_ONE_TIME_TOKEN` returns a one-time token, for passing in a URL. `WOPITOKEN_TYPE_WOPICONTAINER_TOKEN` is rejected. Values: `WOPITOKEN_TYPE_WOPIVAULT_USER_SESSION_TOKEN` (0), `WOPITOKEN_TYPE_ONE_TIME_TOKEN` (1), `WOPITOKEN_TYPE_WOPICONTAINER_TOKEN` (2). |

<a id="response"></a>

## Response: CreateWOPIUserSessionResponse

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `wopi_key` | `string` | The token of the requested type. |

<a id="related"></a>

## Related methods

- [IRPCWOPIOperationsPublic.GetWOPIUserSessionKey](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCWOPIOperationsPublic/GetWOPIUserSessionKey/index.md): Exchanges a one-time token for the WOPI user session token it stands for.
