Generates an access credential for document preview and editing.
Operation description
-
Before you use this API, make sure that you fully understand the billing methods and pricing of Intelligent Media Management (IMM).
-
The access credential expires in 30 minutes. The refresh credential expires in 1 day.
-
The returned expiration time is in UTC. This is 8 hours behind UTC+8.
-
Supported input file formats:
Word processing documents (Word): doc, docx, txt, dot, wps, wpt, dotx, docm, dotm, and rtf.
Presentation documents (PPT): ppt, pptx, pptm, ppsx, ppsm, pps, potx, potm, dpt, and dps.
Spreadsheet documents (Excel): et, xls, xlt, xlsx, xlsm, xltx, xltm, and csv.
PDF documents: pdf.
-
The maximum file size is 200 MB.
-
The maximum number of pages is 5,000.
-
For projects created before December 1, 2023, billing is based on the number of times a document is opened. For new projects, billing is based on the number of API calls. To switch to the new billing model, you must create a new project. Note that a single API call can be used by only one user. If the same API call is used by multiple users, only the last user can access the document, and the access permissions of other users are revoked.
-
Activate Message Service (MNS) in the same region as IMM. Create a topic and a queue, and then configure a subscription relationship. You can then pass the MNS topic name in the NotifyTopicName parameter to receive notifications when a file is saved. For more information about the MNS software development kit (SDK), see Receive and delete messages. For an example of the JSON format of the Message field in a file save notification, see WebOffice notification message format.
To use the multi-version feature, you must first enable it in Object Storage Service (OSS) and then set the History parameter to true.
Try it now
Test
RAM authorization
|
Action |
Access level |
Resource type |
Condition key |
Dependent action |
|
imm:GenerateWebofficeToken |
none |
*Project
|
None | None |
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
| ProjectName |
string |
Yes |
The project name. For more information about how to obtain the project name, see Create a project. |
test-project |
| SourceURI |
string |
Yes |
The OSS URL of the document to preview or edit. The URL must be in the format of |
oss://test-bucket/test-object.docx |
| Filename |
string |
No |
The file name, which must include the file name extension. The default value is the last part of the SourceURI parameter. Supported file name extensions (PDF files are view-only):
|
test-Object.pptx |
| CachePreview |
boolean |
No |
Specifies whether to cache the preview:
Important The unit price for cached previews is different from non-cached previews. For more information, see the billing description.
Important Document content search and printing are not supported in cached preview mode. Important Updating cached content is not currently supported. |
true、false |
| Referer |
string |
No |
OSS hotlink protection. IMM needs to get the source file from OSS. If hotlink protection is configured for OSS, IMM must pass the corresponding header to OSS to get the source file. Note
If the bucket where the document is located has a Referer configured, set this parameter. |
* |
| UserData |
string |
No |
Custom user information. This parameter takes effect only when the Notification parameter is configured for MNS. The information is returned in the asynchronous notification message to help you associate notifications within your system. The maximum length is 2,048 bytes. |
{ "id": "test-id", "name": "test-name" } |
| PreviewPages |
integer |
No |
Limits the preview to the first few pages. By default, there is no limit. The maximum value is 5,000. |
5 |
| Password |
string |
No |
The password to open the document. Note
Set this parameter to preview or edit a password-protected document. |
123456 |
| ExternalUploaded |
boolean |
No |
Specifies whether uploading a file with the same name to OSS is an expected behavior. Valid values:
|
false |
| NotifyTopicName |
string |
No |
Sends notifications for certain events to customers as MNS messages. This parameter is the topic for asynchronous MNS notifications. |
test-topic |
| Hidecmb |
boolean |
No |
Specifies whether to hide the toolbar. This parameter is supported in document preview mode. Valid values:
|
false |
| Permission | WebofficePermission |
No |
User permission information, in JSON format. User permissions include the following options: Each option is of the Boolean type. The default value is false. Valid values are true and false.
Note
PDF files only support the preview feature. You must set the Readonly parameter to true. Note
Exporting is not supported for PDF files. Note
To use the multi-version feature, you must first enable it in OSS and then set the History parameter to true. Important Printing is not supported in cached preview mode. Important You can view historical versions in edit mode. Viewing historical versions is not supported in preview mode. |
|
| User | WebofficeUser |
No |
User information. You can pass user information from your business side. The WebOffice page will display this information. The system uses User.Id to distinguish between different users. User.Name is only for display on the frontend. If User.Id is not passed, the backend automatically generates a random ID. Users with different IDs are treated as different entities and cannot modify or delete each other's comments. The default format is: Unknown_random_string. If User.Id is not passed, the user information defaults to "Unknown". |
|
| Watermark | WebofficeWatermark |
No |
Watermark information. The watermark is generated on the frontend and is not written to the source document. Passing different parameters for the same document results in different watermarks. |
|
| CredentialConfig | CredentialConfig |
No |
If you have no special requirements, leave this parameter empty. The chained authorization configuration. This parameter is optional. For more information, see Use chained authorization to access resources of other entities. |
|
| Notification | Notification |
No |
The configuration for notification messages. Currently, only MNS is supported. For the format of asynchronous notification messages, see WebOffice notification message format. Note
Notification messages are sent when a file is saved or renamed. |
Typical scenarios
The following examples show the parameter structure for each scenario.
Preview a file in read-only mode (required for PDF files)
To preview a document in read-only mode:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.pdf",
"Filename" : "test-object.docx",
"PreviewPages" : "5",
"Permission" : "{'Readonly':'true'}"
}
Preview a file with an uppercase file name extension
To preview a file with an uppercase file name extension, set the Filename parameter with a lowercase extension:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.DOCX",
"Filename" : "test-object.docx",
"PreviewPages" : "5",
"Permission" : "{'Readonly':'true'}"
}
Preview only the first 5 pages of a document
To display only the first 5 pages of a 10-page document:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"PreviewPages" : "5",
"Permission" : "{'Readonly':'true'}"
}
Add a password for document preview
To set a password for a document preview, or to open a password-protected source file for preview without a password prompt:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Password" : "123456",
"Permission" : "{'Readonly':'true'}"
}
Add a watermark to a document preview
To add a watermark during a document preview:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Watermark" : "{'Type':'1','Value':'watermark_value','Font':'bold 20px Serif'}",
"Permission" : "{'Readonly':'true'}"
}
Hide the toolbar during document preview
To hide the toolbar during a document preview:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Hidecmb" : "true",
"Permission" : "{'Readonly':'true'}"
}
Grant permissions to edit online, view history, copy, print, and export to PDF
To grant permissions to edit online, view history, copy, print, and export to PDF:
{
"ProjectName" : "test-project",
"SourceURI" : "oss://test-bucket/test-object.docx",
"Filename" : "test-object.docx",
"Permission" : "{'Readonly':'false','History':'true','Copy':'true','Print':'true','Export':'true'}"
}
Response elements
|
Element |
Type |
Description |
Example |
|
object |
The Weboffice access credential. |
||
| RequestId |
string |
The request ID. |
1759315A-CB33-0A75-A72B-62D7******** |
| WebofficeURL |
string |
The entry URL for Weboffice. Use this URL to preview or edit the document online. Note
You cannot open this URL directly in a browser. You must use it with the Weboffice JS SDK and an access credential (AccessToken) to preview or edit the document. For more information, see Quick Start. |
https://office-cn-shanghai.imm.aliyuncs.com/office/s/dd221b2cdb44fb66e9070d1d70a8b9bbb6d6fff7?_w_tokentype=1 |
| AccessToken |
string |
The Weboffice access credential. |
2d73dd5d87524c5e8a194c3eb5******** |
| RefreshToken |
string |
The Weboffice refresh credential. |
e374995ec532432bb678074d36******** |
| AccessTokenExpiredTime |
string |
The expiration time of the access credential. The credential expires in 30 minutes. |
2021-08-30T13:13:11.347146982Z |
| RefreshTokenExpiredTime |
string |
The expiration time of the refresh credential. The credential expires in 1 day. |
2021-08-31T12:43:11.347146982Z |
Common errors
The project that corresponds to `ProjectName` was not found. Go to the new IMM console to check whether the project exists in the specified region.
{
"Code": "ResourceNotFound",
"Message": "The specified resource acs:imm::xxx:project/xxx is not found"
}
The `User` parameter is required. Check whether this parameter is specified.
{
"Code": "InvalidArgument.User",
"Message": "The parameter User is required but not provided"
}
The `User` parameter is invalid. Check whether the parameter value is in the correct JSON format.
{
"Code": "InvalidJSON parsing error, User",
"Message": "Specified parameter JSON parsing error, User is not valid."
}
The `Permission` parameter is invalid. Check whether the parameter value is in the correct JSON format.
{
"Code": "InvalidJSON parsing error, Permission",
"Message": "Specified parameter JSON parsing error, Permission is not valid."
}
The `Watermark` parameter is invalid. Check whether the parameter value is in the correct JSON format.
{
"Code": "InvalidJSON parsing error, Watermark",
"Message": "Specified parameter JSON parsing error, Watermark is not valid."
}
The format of the `PreviewPages` parameter is invalid. Check the value of this parameter.
{
"Code": "InvalidPreviewPages",
"Message": "Specified parameter PreviewPages is not valid."
}
The OSS file that corresponds to `SourceURI` does not exist. Check whether the file exists in the OSS bucket.
{
"Code": "ResourceNotFound",
"Message": "The specified resource oss://xx is not found"
}
Examples
Success response
JSON format
{
"RequestId": "1759315A-CB33-0A75-A72B-62D7********",
"WebofficeURL": "https://office-cn-shanghai.imm.aliyuncs.com/office/s/dd221b2cdb44fb66e9070d1d70a8b9bbb6d6fff7?_w_tokentype=1",
"AccessToken": "2d73dd5d87524c5e8a194c3eb5********",
"RefreshToken": "e374995ec532432bb678074d36********",
"AccessTokenExpiredTime": "2021-08-30T13:13:11.347146982Z",
"RefreshTokenExpiredTime": "2021-08-31T12:43:11.347146982Z"
}
Error codes
See Error Codes for a complete list.
Release notes
See Release Notes for a complete list.