1# @ohos.data.cloudData (Cloud Service) (System API) 2 3The **cloudData** module provides APIs for implementing device-cloud synergy and device-cloud sharing and setting the device-cloud sync strategy. 4 5Device-cloud synergy enables sync of the structured data (in RDB stores) between devices and the cloud. The cloud serves as a data hub to implement data backup in the cloud and data consistency between the devices with the same account. 6 7Device-cloud sharing enables data sharing across accounts based on device-cloud synergy. Understanding the following concepts helps you better understand the device-cloud sharing process: 8 9- **sharingResource**: an identifier of the string type generated for each data record shared by an application before device-cloud sync is performed. It uniquely identifies the data record being shared. 10- **Participant**: all participants involved in a share, including the inviter and invitees. 11 12- **invitationCode**: an invitation code generated by the share server for a share operation. It is generated after a data share is initiated and attached to an invitation pushed to the devices of target invitees. The target invitees then confirm the invitation via this code. 13 14The **cloudData** module provides the following functionalities: 15 16- [Config](#config): provides APIs for setting device-cloud synergy, including enabling and disabling device-cloud sync, clearing data, and notifying data changes. 17- [sharing](#sharing11): provides APIs for device-cloud data sharing, including sharing or unsharing data, exiting a share, changing the privilege on the shared data, querying participants, confirming an invitation, changing the invitation confirmation state, and querying the shared resource. 18 19> **NOTE** 20> 21> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 22> 23> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.data.cloudData (Cloud Service)](js-apis-data-cloudData.md). 24> 25> - Before using this module, ensure that the cloud service is available. 26 27## Modules to Import 28 29```ts 30import { cloudData } from '@kit.ArkData'; 31``` 32 33## ClearAction 34 35Enumerates the operations for clearing the downloaded cloud data locally. 36 37**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 38 39| Name | Description | 40| --------- | ---------------------------- | 41| CLEAR_CLOUD_INFO | Clear the cloud identifier of the data downloaded from the cloud and retain the data locally.| 42| CLEAR_CLOUD_DATA_AND_INFO |Clear the data downloaded from the cloud, excluding the cloud data that has been modified locally. | 43 44## ExtraData<sup>11+</sup> 45 46Represents the transparently transmitted data, which contains information required for a data change notification. 47 48**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 49 50| Name | Type | Mandatory| Description | 51| --------- | ------ | ---- | ------------------------------------------------------------ | 52| eventId | string | Yes | Event ID. The value **cloud_data_change** indicates cloud data changes. | 53| extraData | string | Yes | Data to be transmitted transparently. <br/>**extraData** is a JSON string that must contain the **data** field. The **data** field contains information required for a change notification, including the account ID, application name, database name, database type, and database table name. All the fields cannot be empty. | 54 55**Example** 56 57```ts 58// accountId: ID of the cloud account. 59// bundleName: application bundle name. 60// containerName: name of the cloud database. 61// databaseScopes: type of the cloud database. 62// recordTypes: names of the tables in the cloud database. 63 64interface ExtraData { 65 eventId: "cloud_data_change", 66 extraData: '{ 67 "data": "{ 68 "accountId": "aaa", 69 "bundleName": "com.bbb.xxx", 70 "containerName": "alias", 71 "databaseScopes": ["private", "shared"], 72 "recordTypes": ["xxx", "yyy", "zzz"] 73 }" 74 }' 75} 76 77``` 78 79## StatisticInfo<sup>12+</sup> 80 81Represents the device-cloud sync statistics. 82 83**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 84 85| Name | Type | Mandatory| Description | 86| --------- | ------ | ---- |-----------------------------------------------------| 87| table | string | Yes | Name of the table queried. For example, the value **cloud_notes** indicates that the sync information of the **cloud_notes** table is queried.| 88| inserted | number | Yes | Number of data records that are added locally and have not been synced to the cloud. For example, the value **2** indicates that the table has two data records that are added locally but not synced to the cloud. | 89| updated | number | Yes | Number of data records that are modified locally or on the cloud but have not been synced. For example, the value **2** indicates that the table has two data records that are updated locally or on the cloud but not synced. | 90| normal | number | Yes | Number of consistent data records between the device and the cloud. For example, the value **2** indicates that table has two data records that are consistent between the device and the cloud. | 91 92## SyncStatus<sup>18+</sup> 93 94Enumerates the device-cloud sync task statuses. 95 96**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 97 98| Name | Value | Description | 99| -------- |-----|-----------------| 100| RUNNING | 0 | The device-cloud sync task is running.| 101| FINISHED | 1 | The device-cloud sync task is completed.| 102 103## SyncInfo<sup>12+</sup> 104 105Represents information about the last device-cloud sync. 106 107**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 108 109| Name | Type | Mandatory| Description | 110| ---------- | ------------------------------------------------------------ | ---- | -------------------------- | 111| startTime | Date | Yes | Start time of the last device-cloud sync.| 112| finishTime | Date | Yes | End time of the last device-cloud sync.| 113| code | [relationalStore.ProgressCode](js-apis-data-relationalStore.md#progresscode10) | Yes | Result of the last device-cloud sync.| 114| syncStatus<sup>18+</sup> | [SyncStatus](#syncstatus18) | No| Status of the last device-cloud sync. The default value is **cloudData.SyncStatus.RUNNING**.| 115 116## Config 117 118Provides APIs for setting device-cloud synergy, including enabling and disabling device-cloud synergy, clearing data, and notifying data changes. 119 120### enableCloud 121 122static enableCloud(accountId: string, switches: Record<string, boolean>, callback: AsyncCallback<void>): void 123 124Enables device-cloud synergy. This API uses an asynchronous callback to return the result. 125 126**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 127 128**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 129 130**Parameters** 131 132| Name | Type | Mandatory| Description | 133| --------- | ------------------------------- | ---- | ------------------------------------------------------------ | 134| accountId | string | Yes | ID of the cloud account. | 135| switches | Record<string, boolean> | Yes | Device-cloud synergy settings for applications. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 136| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 137 138**Error codes** 139 140For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 141 142| ID| Error Message | 143| -------- | ---------------------------------------------------- | 144| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 145| 202 | Permission verification failed, application which is not a system application uses system API.| 146| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 147| 801 | Capability not supported.| 148 149**Example** 150 151```ts 152import { BusinessError } from '@kit.BasicServicesKit'; 153 154let account: string = 'test_id'; 155let switches: Record<string, boolean> = { 'test_bundleName1': true, 'test_bundleName2': false }; 156try { 157 cloudData.Config.enableCloud(account, switches, (err: BusinessError) => { 158 if (err === undefined) { 159 console.info('Succeeded in enabling cloud'); 160 } else { 161 console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`); 162 } 163 }); 164} catch (e) { 165 let error = e as BusinessError; 166 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 167} 168``` 169 170### enableCloud 171 172static enableCloud(accountId: string, switches: Record<string, boolean>): Promise<void> 173 174Enables device-cloud synergy. This API uses a promise to return the result. 175 176**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 177 178**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 179 180**Parameters** 181 182| Name | Type | Mandatory| Description | 183| --------- | ------------------------------- | ---- | ------------------------------------------------------------ | 184| accountId | string | Yes | ID of the cloud account. | 185| switches | Record<string, boolean> | Yes | Device-cloud synergy settings for applications. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 186 187**Return value** 188 189| Type | Description | 190| ------------------- | ------------------------- | 191| Promise<void> | Promise that returns no value.| 192 193**Error codes** 194 195For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 196 197| ID| Error Message | 198| -------- | ---------------------------------------------------- | 199| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 200| 202 | Permission verification failed, application which is not a system application uses system API.| 201| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 202| 801 | Capability not supported.| 203 204**Example** 205 206```ts 207import { BusinessError } from '@kit.BasicServicesKit'; 208 209let account: string = 'test_id'; 210let switches: Record<string, boolean> = { 'test_bundleName1': true, 'test_bundleName2': false }; 211try { 212 cloudData.Config.enableCloud(account, switches).then(() => { 213 console.info('Succeeded in enabling cloud'); 214 }).catch((err: BusinessError) => { 215 console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`); 216 }); 217} catch (e) { 218 let error = e as BusinessError; 219 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 220} 221``` 222 223### disableCloud 224 225static disableCloud(accountId: string, callback: AsyncCallback<void>): void 226 227Disables device-cloud synergy. This API uses an asynchronous callback to return the result. 228 229**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 230 231**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 232 233**Parameters** 234 235| Name | Type | Mandatory| Description | 236| --------- | ------------------------- | ---- | -------------------- | 237| accountId | string | Yes | ID of the cloud account.| 238| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 239 240**Error codes** 241 242For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 243 244| ID| Error Message | 245| -------- | ---------------------------------------------------- | 246| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 247| 202 | Permission verification failed, application which is not a system application uses system API.| 248| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 249| 801 | Capability not supported.| 250 251**Example** 252 253```ts 254import { BusinessError } from '@kit.BasicServicesKit'; 255 256let account: string = 'test_id'; 257try { 258 cloudData.Config.disableCloud(account, (err: BusinessError) => { 259 if (err === undefined) { 260 console.info('Succeeded in disabling cloud'); 261 } else { 262 console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`); 263 } 264 }); 265} catch (e) { 266 let error = e as BusinessError; 267 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 268} 269``` 270 271### disableCloud 272 273static disableCloud(accountId: string): Promise<void> 274 275Disables device-cloud synergy. This API uses a promise to return the result. 276 277**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 278 279**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 280 281**Parameters** 282 283| Name | Type | Mandatory| Description | 284| --------- | ------ | ---- | -------------------- | 285| accountId | string | Yes | ID of the cloud account.| 286 287**Return value** 288 289| Type | Description | 290| ------------------- | ------------------------- | 291| Promise<void> | Promise that returns no value.| 292 293**Error codes** 294 295For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 296 297| ID| Error Message | 298| -------- | ---------------------------------------------------- | 299| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 300| 202 | Permission verification failed, application which is not a system application uses system API.| 301| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 302| 801 | Capability not supported.| 303 304**Example** 305 306```ts 307import { BusinessError } from '@kit.BasicServicesKit'; 308 309let account: string = 'test_id'; 310try { 311 cloudData.Config.disableCloud(account).then(() => { 312 console.info('Succeeded in disabling cloud'); 313 }).catch((err: BusinessError) => { 314 console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`); 315 }); 316} catch (e) { 317 let error = e as BusinessError; 318 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 319} 320``` 321 322### changeAppCloudSwitch 323 324static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void 325 326Changes the device-cloud synergy setting for an application. This API uses an asynchronous callback to return the result. 327 328**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 329 330**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 331 332**Parameters** 333 334| Name | Type | Mandatory| Description | 335| --------- | ------------------------------- | ---- | ---------------------------- | 336| accountId | string | Yes | ID of the cloud account.| 337| bundleName| string | Yes | Bundle name of the application.| 338| status | boolean | Yes | New device-cloud synergy setting. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 339| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 340 341**Error codes** 342 343For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 344 345| ID| Error Message | 346| -------- | ---------------------------------------------------- | 347| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 348| 202 | Permission verification failed, application which is not a system application uses system API.| 349| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 350| 801 | Capability not supported.| 351 352**Example** 353 354```ts 355import { BusinessError } from '@kit.BasicServicesKit'; 356 357let account: string = 'test_id'; 358let bundleName: string = 'test_bundleName'; 359try { 360 cloudData.Config.changeAppCloudSwitch(account, bundleName, true, (err: BusinessError) => { 361 if (err === undefined) { 362 console.info('Succeeded in changing App cloud switch'); 363 } else { 364 console.error(`Failed to change App cloud switch. Code: ${err.code}, message: ${err.message}`); 365 } 366 }); 367} catch (e) { 368 let error = e as BusinessError; 369 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 370} 371``` 372 373### changeAppCloudSwitch 374 375static changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void> 376 377Changes the device-cloud synergy setting for an application. This API uses a promise to return the result. 378 379**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 380 381**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 382 383**Parameters** 384 385| Name | Type | Mandatory| Description | 386| --------- | ------------------------------- | ---- | ---------------------------- | 387| accountId | string | Yes | ID of the cloud account.| 388| bundleName| string | Yes | Bundle name of the application.| 389| status | boolean | Yes | New device-cloud synergy setting. The value **true** means to enable device-cloud synergy; the value **false** means the opposite.| 390 391**Return value** 392 393| Type | Description | 394| ------------------- | ------------------------- | 395| Promise<void> | Promise that returns no value.| 396 397**Error codes** 398 399For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 400 401| ID| Error Message | 402| -------- | ---------------------------------------------------- | 403| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 404| 202 | Permission verification failed, application which is not a system application uses system API.| 405| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 406| 801 | Capability not supported.| 407 408**Example** 409 410```ts 411import { BusinessError } from '@kit.BasicServicesKit'; 412 413let account: string = 'test_id'; 414let bundleName: string = 'test_bundleName'; 415try { 416 cloudData.Config.changeAppCloudSwitch(account, bundleName, true).then(() => { 417 console.info('Succeeded in changing App cloud switch'); 418 }).catch((err: BusinessError) => { 419 console.error(`Failed to change App cloud switch. Code is ${err.code}, message is ${err.message}`); 420 }); 421} catch (e) { 422 let error = e as BusinessError; 423 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 424} 425``` 426 427### notifyDataChange 428 429static notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void 430 431Notifies the data changes in the cloud. This API uses an asynchronous callback to return the result. 432 433**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 434 435**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 436 437**Parameters** 438 439| Name | Type | Mandatory| Description | 440| ---------- | ------------------------- | ---- | -------------------- | 441| accountId | string | Yes | ID of the cloud account.| 442| bundleName | string | Yes | Bundle name of the application. | 443| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 444 445**Error codes** 446 447For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 448 449| ID| Error Message | 450| -------- | ---------------------------------------------------- | 451| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 452| 202 | Permission verification failed, application which is not a system application uses system API.| 453| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 454| 801 | Capability not supported.| 455 456**Example** 457 458```ts 459import { BusinessError } from '@kit.BasicServicesKit'; 460 461let account: string = 'test_id'; 462let bundleName: string = 'test_bundleName'; 463try { 464 cloudData.Config.notifyDataChange(account, bundleName, (err: BusinessError) => { 465 if (err === undefined) { 466 console.info('Succeeded in notifying the change of data'); 467 } else { 468 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 469 } 470 }); 471} catch (e) { 472 let error = e as BusinessError; 473 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 474} 475``` 476 477### notifyDataChange 478 479static notifyDataChange(accountId: string,bundleName: string): Promise<void> 480 481Notifies the data changes in the cloud. This API uses a promise to return the result. 482 483**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 484 485**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 486 487**Parameters** 488 489| Name | Type | Mandatory| Description | 490| ---------- | ------ | ---- | -------------------- | 491| accountId | string | Yes | ID of the cloud account.| 492| bundleName | string | Yes | Bundle name of the application. | 493 494**Return value** 495 496| Type | Description | 497| ------------------- | ------------------------- | 498| Promise<void> | Promise that returns no value.| 499 500**Error codes** 501 502For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 503 504| ID| Error Message | 505| -------- | ---------------------------------------------------- | 506| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 507| 202 | Permission verification failed, application which is not a system application uses system API.| 508| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 509| 801 | Capability not supported.| 510 511**Example** 512 513```ts 514import { BusinessError } from '@kit.BasicServicesKit'; 515 516let account: string = 'test_id'; 517let bundleName: string = 'test_bundleName'; 518try { 519 cloudData.Config.notifyDataChange(account, bundleName).then(() => { 520 console.info('Succeeded in notifying the change of data'); 521 }).catch((err: BusinessError) => { 522 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 523 }); 524} catch (e) { 525 let error = e as BusinessError; 526 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 527} 528``` 529 530### notifyDataChange<sup>11+</sup> 531 532 static notifyDataChange(extInfo: ExtraData, callback: AsyncCallback<void>):void 533 534Notifies the data changes in the cloud with the specified information, such as the database and table names (specified by the **extraData** field in **extInfo**). This API uses an asynchronous callback to return the result. 535 536**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 537 538**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 539 540**Parameters** 541 542| Name | Type | Mandatory| Description | 543| -------- | ------------------------- | ---- | --------------------------------------- | 544| extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes.| 545| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 546 547**Error codes** 548 549For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 550 551| ID| Error Message | 552| -------- | ---------------------------------------------------- | 553| 201 | Permission verification failed, which is usually returned by VerifyAccessToken.| 554| 202 | Permission verification failed, application which is not a system application uses system API.| 555| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 556| 801 | Capability not supported.| 557 558**Example** 559 560```ts 561import { BusinessError } from '@kit.BasicServicesKit'; 562 563let eventId: string = "cloud_data_change"; 564let extraData: string = '{"data":"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias", "databaseScopes": ["private", "shared"],"recordTypes":"["xxx","yyy","zzz"]"}"}'; 565try { 566 cloudData.Config.notifyDataChange({ 567 eventId: eventId, extraData: extraData 568 }, (err: BusinessError) => { 569 if (err === undefined) { 570 console.info('Succeeded in notifying the change of data'); 571 } else { 572 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 573 } 574 }); 575} catch (e) { 576 let error = e as BusinessError; 577 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 578} 579``` 580 581### notifyDataChange<sup>11+</sup> 582 583static notifyDataChange(extInfo: ExtraData, userId: number,callback: AsyncCallback<void>):void 584 585Notifies the data changes of a user in the cloud. This API uses an asynchronous callback to return the result. You can also specify the database and tables with data changes in the **extraData** field in **extInfo**. 586 587**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 588 589**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 590 591**Parameters** 592 593| Name | Type | Mandatory| Description | 594| -------- | ------------------------- | ---- | ----------------------------------------------- | 595| extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes. | 596| userId | number | Yes | User ID in the system.| 597| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 598 599**Error codes** 600 601For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 602 603| ID| Error Message | 604| -------- | ---------------------------------------------------- | 605| 201 | Permission verification failed, which is usually returned by VerifyAccessToken.| 606| 202 | Permission verification failed, application which is not a system application uses system API.| 607| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 608| 801 | Capability not supported.| 609 610**Example** 611 612```ts 613import { BusinessError } from '@kit.BasicServicesKit'; 614 615let eventId: string = "cloud_data_change"; 616let extraData: string = '{"data":"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias", "databaseScopes": ["private", "shared"],"recordTypes":"["xxx","yyy","zzz"]"}"}'; 617let userId: number = 100; 618try { 619 cloudData.Config.notifyDataChange({ 620 eventId: eventId, extraData: extraData 621 }, userId, (err: BusinessError) => { 622 if (err === undefined) { 623 console.info('Succeeded in notifying the change of data'); 624 } else { 625 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 626 } 627 }); 628} catch (e) { 629 let error = e as BusinessError; 630 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 631} 632``` 633 634### notifyDataChange<sup>11+</sup> 635 636static notifyDataChange(extInfo: ExtraData, userId?: number): Promise<void> 637 638Notifies the data changes in the cloud. This API uses a promise to return the result. You can specify the database and tables with data changes in the **extraData** field in **extInfo**, and specify the user ID. 639 640**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 641 642**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 643 644**Parameters** 645 646| Name | Type | Mandatory| Description | 647| ------- | ----------------------- | ---- | ----------------------------------------------- | 648| extInfo | [ExtraData](#extradata11) | Yes | Transparently transmitted data, including information about the application that has data changes. | 649| userId | number | No | User ID. This parameter is optional. The default value is the current user ID. If this parameter is specified, the value must be an existing user ID in the system.| 650 651**Return value** 652 653| Type | Description | 654| ------------------- | ------------------------- | 655| Promise<void> | Promise that returns no value.| 656 657**Error codes** 658 659For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 660 661| ID| Error Message | 662| -------- | ---------------------------------------------------- | 663| 201 | Permission verification failed, which is usually returned by VerifyAccessToken.| 664| 202 | Permission verification failed, application which is not a system application uses system API.| 665| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 666| 801 | Capability not supported.| 667 668**Example** 669 670```ts 671import { BusinessError } from '@kit.BasicServicesKit'; 672 673let eventId: string = "cloud_data_change"; 674let extraData: string = '{"data":"{"accountId":"aaa","bundleName":"com.bbb.xxx","containerName":"alias", "databaseScopes": ["private", "shared"],"recordTypes":"["xxx","yyy","zzz"]"}"}'; 675let userId: number = 100; 676try { 677 cloudData.Config.notifyDataChange({ 678 eventId: eventId, extraData: extraData 679 }, userId).then(() => { 680 console.info('Succeeded in notifying the change of data'); 681 }).catch((err: BusinessError) => { 682 console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`); 683 }); 684} catch (e) { 685 let error = e as BusinessError; 686 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 687} 688``` 689 690### queryStatistics<sup>12+</sup> 691 692static queryStatistics(accountId: string, bundleName: string, storeId?: string): Promise<Record<string, Array<StatisticInfo>>> 693 694Queries device-cloud data statistics, which include the data not synced, data synced and consistent, and data synced but inconsistent between the device and the cloud. This API uses a promise to return the result. 695 696**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 697 698**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 699 700**Parameters** 701 702| Name | Type | Mandatory| Description | 703| ------- |---------| ---- |-----------------------------------| 704| accountId | string | Yes | ID of the cloud account. | 705| bundleName | string | Yes | Bundle name of the application. | 706| storeId | string | No | Name of the RDB store. If this parameter is not specified, all local databases of this application are queried by default.| 707 708**Return value** 709 710| Type | Description | 711|--------------------------------------------------------------------------------------| ------------------------ | 712| Promise<Record<string, Array<[StatisticInfo](#statisticinfo12)>>> | Promise used to return the table name and statistics.| 713 714**Error codes** 715 716For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 717 718| ID| Error Message | 719| -------- | ---------------------------------------------------- | 720| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 721| 202 | Permission verification failed, application which is not a system application uses system API.| 722| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 723| 801 | Capability not supported.| 724 725**Example** 726 727```ts 728import { BusinessError } from '@kit.BasicServicesKit'; 729 730const accountId:string = "accountId"; 731const bundleName:string = "bundleName"; 732const storeId:string = "storeId"; 733 734cloudData.Config.queryStatistics(accountId, bundleName, storeId).then((result) => { 735 console.info(`Succeeded in querying statistics. Info is ${JSON.stringify(result)}`); 736}).catch((err: BusinessError) => { 737 console.error(`Failed to query statistics. Error code is ${err.code}, message is ${err.message}`); 738}); 739``` 740 741### queryLastSyncInfo<sup>12+</sup> 742 743static queryLastSyncInfo(accountId: string, bundleName: string, storeId?: string): Promise<Record<string, SyncInfo>> 744 745Queries information about the last device-cloud sync. This API uses a promise to return the result. 746 747**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 748 749**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 750 751**Parameters** 752 753| Name | Type | Mandatory| Description | 754| ---------- | ------ | ---- | ------------------------------------------------------------ | 755| accountId | string | Yes | ID of the cloud account. | 756| bundleName | string | Yes | Bundle name of the application. | 757| storeId | string | No | Name of the RDB store. The default value is an empty string. If the default value is used, this API queries the last device-cloud sync information of all databases of this application.| 758 759**Return value** 760 761| Type | Description | 762| ------------------------------------------------------------ | -------------------------------------------- | 763| Promise<Record<string, [SyncInfo](#syncinfo12)>> | Promise used to return the database name and the result set of the last device-cloud sync.| 764 765**Error codes** 766 767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 768 769| ID| Error Message | 770| -------- | ---------------------------------------------------- | 771| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 772| 202 | Permission verification failed, application which is not a system application uses system API.| 773| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 774| 801 | Capability not supported.| 775 776**Example** 777 778```ts 779import { BusinessError } from '@kit.BasicServicesKit'; 780 781const accountId:string = "accountId"; 782const bundleName:string = "bundleName"; 783const storeId:string = "storeId"; 784try { 785 cloudData.Config.queryLastSyncInfo(accountId, bundleName, storeId).then((result) => { 786 console.info(`Succeeded in querying last syncinfo. Info is ${JSON.stringify(result)}`); 787 }).catch((err: BusinessError) => { 788 console.error(`Failed to query last syncinfo. Error code is ${err.code}, message is ${err.message}`); 789 }); 790} catch(e) { 791 let error = e as BusinessError; 792 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 793} 794``` 795 796### setGlobalCloudStrategy<sup>12+</sup> 797 798static setGlobalCloudStrategy(strategy: StrategyType, param?: Array<commonType.ValueType>): Promise<void> 799 800Sets a global device-cloud sync strategy. This API uses a promise to return the result. 801 802**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 803 804**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 805 806**Parameters** 807 808| Name | Type | Mandatory| Description | 809| ---------- |------------------------------------------------------------------------| ---- |-------------------| 810| strategy | [StrategyType](js-apis-data-cloudData.md#strategytype) | Yes | Type of the strategy to set. | 811| param | Array<[commonType.ValueType](js-apis-data-commonType.md#valuetype)> | No | Strategy parameters to set. If this parameter is not specified, the strategy configuration is deleted by default. | 812 813**Return value** 814 815| Type | Description | 816| ------------------- | ------------------------- | 817| Promise<void> | Promise that returns no value.| 818 819**Error codes** 820 821For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 822 823| ID| Error Message | 824| -------- | ---------------------------------------------------- | 825| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 826| 202 | Permission verification failed, application which is not a system application uses system API.| 827| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 828| 801 | Capability not supported.| 829 830**Example** 831 832```ts 833import { BusinessError } from '@kit.BasicServicesKit'; 834 835cloudData.Config.setGlobalCloudStrategy(cloudData.StrategyType.NETWORK, [cloudData.NetWorkStrategy.WIFI]).then(() => { 836 console.info('Succeeded in setting the global cloud strategy'); 837}).catch((err: BusinessError) => { 838 console.error(`Failed to set global cloud strategy. Code: ${err.code}, message: ${err.message}`); 839}); 840``` 841 842### clear 843 844static clear(accountId: string, appActions: Record<string, ClearAction>, callback: AsyncCallback<void>): void 845 846Clears the cloud data locally. This API uses an asynchronous callback to return the result. 847 848**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 849 850**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 851 852**Parameters** 853 854| Name | Type | Mandatory| Description | 855| ---------- | --------------------------------------------------- | ---- | -------------------------------- | 856| accountId | string | Yes | ID of the cloud account. | 857| appActions | Record<string, [ClearAction](#clearaction)> | Yes | Information about the application whose data is to be cleared and the operation to perform.| 858| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 859 860**Error codes** 861 862For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 863 864| ID| Error Message | 865| -------- | ---------------------------------------------------- | 866| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 867| 202 | Permission verification failed, application which is not a system application uses system API.| 868| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 869| 801 | Capability not supported.| 870 871**Example** 872 873```ts 874import { BusinessError } from '@kit.BasicServicesKit'; 875 876let account: string = "test_id"; 877type dataType = Record<string, cloudData.ClearAction> 878let appActions: dataType = { 879 'test_bundleName1': cloudData.ClearAction.CLEAR_CLOUD_INFO, 880 'test_bundleName2': cloudData.ClearAction.CLEAR_CLOUD_DATA_AND_INFO 881}; 882try { 883 cloudData.Config.clear(account, appActions, (err: BusinessError) => { 884 if (err === undefined) { 885 console.info('Succeeding in clearing cloud data'); 886 } else { 887 console.error(`Failed to clear cloud data. Code: ${err.code}, message: ${err.message}`); 888 } 889 }); 890} catch (e) { 891 let error = e as BusinessError; 892 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 893} 894``` 895 896### clear 897 898static clear(accountId: string, appActions: Record<string, ClearAction>): Promise<void> 899 900Clears the cloud data locally. This API uses a promise to return the result. 901 902**Required permissions**: ohos.permission.CLOUDDATA_CONFIG 903 904**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config 905 906**Parameters** 907 908| Name | Type | Mandatory| Description | 909| ---------- | --------------------------------------------------- | ---- | -------------------------------- | 910| accountId | string | Yes | ID of the cloud account. | 911| appActions | Record<string, [ClearAction](#clearaction)> | Yes | Information about the application whose data is to be cleared and the operation to perform.| 912 913**Return value** 914 915| Type | Description | 916| ------------------- | ------------------------- | 917| Promise<void> | Promise that returns no value.| 918 919**Error codes** 920 921For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 922 923| ID| Error Message | 924| -------- | ---------------------------------------------------- | 925| 201 | Permission verification failed, usually the result returned by VerifyAccessToken.| 926| 202 | Permission verification failed, application which is not a system application uses system API.| 927| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 928| 801 | Capability not supported.| 929 930**Example** 931 932```ts 933import { BusinessError } from '@kit.BasicServicesKit'; 934 935let account: string = "test_id"; 936type dataType = Record<string, cloudData.ClearAction>; 937let appActions: dataType = { 938 'test_bundleName1': cloudData.ClearAction.CLEAR_CLOUD_INFO, 939 'test_bundleName2': cloudData.ClearAction.CLEAR_CLOUD_DATA_AND_INFO 940}; 941try { 942 cloudData.Config.clear(account, appActions).then(() => { 943 console.info('Succeeding in clearing cloud data'); 944 }).catch((err: BusinessError) => { 945 console.error(`Failed to clear cloud data. Code: ${err.code}, message: ${err.message}`); 946 }); 947} catch (e) { 948 let error = e as BusinessError; 949 console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`); 950} 951``` 952 953## sharing<sup>11+</sup> 954 955Provides APIs for device-cloud data sharing, including sharing or unsharing data, exiting a share, changing the privilege on the shared data, querying participants, confirming an invitation, changing the invitation confirmation state, and querying the shared resource. 956 957### Role<sup>11+</sup> 958 959Enumerates the roles of the participants in a device-cloud share. 960 961**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 962 963| Name | Value | Description | 964| --------------| ---- | ---------------------------------- | 965| ROLE_INVITER | 0 | Inviter, the one who shares data. Use the enum name rather than the enum value.| 966| ROLE_INVITEE | 1 | Invitee, the one who can use the shared data. Use the enum name rather than the enum value.| 967 968### State<sup>11+</sup> 969 970Enumerates the device-cloud sharing states. 971 972**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 973 974| Name | Value | Description | 975| --------------| ---- | ---------------------------------- | 976| STATE_UNKNOWN | 0 | Unknown state. Use the enum name rather than the enum value. | 977| STATE_ACCEPTED | 1 | The device-cloud sharing invitation is accepted. Use the enum name rather than the enum value.| 978| STATE_REJECTED | 2 | The device-cloud sharing invitation is rejected. Use the enum name rather than the enum value.| 979| STATE_SUSPENDED | 3 | The device-cloud sharing is suspended temporarily. Use the enum name rather than the enum value.| 980| STATE_UNAVAILABLE<sup>12+</sup> | 4 | The device-cloud sharing is unavailable. Use the enum name rather than the enum value.| 981 982### SharingCode<sup>11+</sup> 983 984Enumerates the error codes for device-cloud sharing. 985 986**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 987 988| Name | Value | Description | 989| --------------| ---- | ---------------------------------- | 990| SUCCESS | 0 | Operation successful. Use the enum name rather than the enum value. | 991| REPEATED_REQUEST | 1 | Repeated invitation, which means the participant has been invited. Use the enum name rather than the enum value.| 992| NOT_INVITER | 2 | The participant is not the inviter of this share. Use the enum name rather than the enum value.| 993| NOT_INVITER_OR_INVITEE | 3 | Invalid participant, which means the participant is neither the inviter nor the invitee. Use the enum name rather than the enum value.| 994| OVER_QUOTA | 4 | The number of device-cloud sharing times has reached the limit for the current account. Use the enum name rather than the enum value. | 995| TOO_MANY_PARTICIPANTS | 5 | The number of device-cloud sharing participants has reached the limit. Use the enum name rather than the enum value.| 996| INVALID_ARGS | 6 | Invalid parameter. Use the enum name rather than the enum value.| 997| NETWORK_ERROR | 7 | Network error. Use the enum name rather than the enum value.| 998| CLOUD_DISABLED | 8 | Cloud is disabled. Use the enum name rather than the enum value. | 999| SERVER_ERROR | 9 | Server error. Use the enum name rather than the enum value.| 1000| INNER_ERROR | 10 | System internal error. Use the enum name rather than the enum value.| 1001| INVALID_INVITATION | 11 | Invalid invitation, which means the current invitation has expired or does not exist. Use the enum name rather than the enum value.| 1002| RATE_LIMIT | 12 | The amount of data to be synced at a time has reached the limit. Use the enum name rather than the enum value. | 1003| CUSTOM_ERROR | 1000 | Customized error. Error codes smaller than **1000** are used to define internal error codes, and error codes greater than **1000** are used to customize error codes. Use the enum name rather than the enum value.| 1004 1005### Result<T><sup>11+</sup> 1006 1007Represents the device-cloud sharing result. 1008 1009**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1010 1011| Name | Type | Mandatory | Description | 1012| ----------- | --------------------------- | --- | ------------ | 1013| code | number | Yes | Error code. | 1014| description | string | No | Detailed description of the error code. The default value is **undefined**. | 1015| value | T | No | Value returned. The specific type is specified by the **T** parameter. The default value is **undefined**.| 1016 1017### Privilege<sup>11+</sup> 1018 1019Defines the privilege (permissions) on the shared data. 1020 1021**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1022 1023| Name | Type | Mandatory | Description | 1024| ----------- | --------------------------- | --- | ------------ | 1025| writable | boolean | No | Whether the participant can modify the shared data. The value **true** means the participant can modify the data; the value **false** means the opposite. The default value is **false**. | 1026| readable | boolean | No | Whether the participant can read the shared data. The value **true** means the participant can read the data; the value **false** means the opposite. The default value is **false**. | 1027| creatable | boolean | No | Whether the participant can create data to share. The value **true** means the participant can create data; the value **false** means the opposite. The default value is **false**. | 1028| deletable | boolean | No | Whether the participant can delete the shared data. The value **true** means the participant can delete the data; the value **false** means the opposite. The default value is **false**. | 1029| shareable | boolean | No | Whether the participant can share the data to others. The value **true** means the participant can share the data; the value **false** means the opposite. The default value is **false**. | 1030 1031### Participant<sup>11+</sup> 1032 1033Represents information about a participant of device-cloud sharing. 1034 1035**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1036 1037| Name | Type | Mandatory | Description | 1038| ----------- | --------------------------- | --- | ------------ | 1039| identity | string | Yes | ID of the participant. | 1040| role | [Role](#role11) | No | Role of the participant, inviter or invitee. The default value is **undefined**. | 1041| state | [State](#state11) | No | State of the device-cloud sharing. The default value is **undefined**.| 1042| privilege | [Privilege](#privilege11) | No | Permissions on the shared data. The [Privilege](#privilege11) defaults are used by default.| 1043| attachInfo | string | No | Additional information, such as the verification code used for participant identity verification. The default value is an empty string.| 1044 1045### allocResourceAndShare<sup>11+</sup> 1046 1047allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, columns?: Array<string>): Promise<relationalStore.ResultSet> 1048 1049Allocates a shared resource ID based on the data that matches the specified predicates. This API uses a promise to return the result set of the data to share, which also includes the column names if they are specified. 1050 1051**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1052 1053**Parameters** 1054 1055| Name | Type | Mandatory| Description | 1056| --------- | ------------------------------- | ---- | ---------------------------- | 1057| storeId | string | Yes | Name of the RDB store.| 1058| predicates | [relationalStore.RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Predicates for matching the data to share.| 1059| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1060| columns | Array<string> | No | Columns in which the data is located. The default value is **undefined**, which means column names are not returned.| 1061 1062**Return value** 1063 1064| Type | Description | 1065| ------------------- | ------------------------- | 1066| Promise<[relationalStore.ResultSet](js-apis-data-relationalStore.md#resultset)> | Promise used to return the result set of the data to share.| 1067 1068**Error codes** 1069 1070For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1071 1072| ID| Error Message | 1073| -------- | ---------------------------------------------------- | 1074| 202 | Permission verification failed, application which is not a system application uses system API.| 1075| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1076| 801 | Capability not supported.| 1077 1078**Example** 1079 1080```ts 1081import { BusinessError } from '@kit.BasicServicesKit'; 1082import { relationalStore } from '@kit.ArkData'; 1083 1084let participants = new Array<cloudData.sharing.Participant>(); 1085participants.push({ 1086 identity: '000000000', 1087 role: cloudData.sharing.Role.ROLE_INVITER, 1088 state: cloudData.sharing.State.STATE_UNKNOWN, 1089 privilege: { 1090 writable: true, 1091 readable: true, 1092 creatable: false, 1093 deletable: false, 1094 shareable: false 1095 }, 1096 attachInfo: '' 1097}) 1098let sharingResource: string; 1099let predicates = new relationalStore.RdbPredicates('test_table'); 1100predicates.equalTo('data', 'data_test'); 1101cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, ['uuid', 'data']).then((resultSet) => { 1102 if (!resultSet.goToFirstRow()) { 1103 console.error(`row error`); 1104 return; 1105 } 1106 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 1107 console.info(`sharing resource: ${res}`); 1108 sharingResource = res; 1109}).catch((err: BusinessError) => { 1110 console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); 1111}) 1112 1113``` 1114 1115### allocResourceAndShare<sup>11+</sup> 1116 1117allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, columns: Array<string>, callback: AsyncCallback<relationalStore.ResultSet>): void 1118 1119Allocates a shared resource ID based on the data that matches the specified predicates. This API uses an asynchronous callback to return the result set of the data to share, which includes the shared resource ID and column names. 1120 1121**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1122 1123**Parameters** 1124 1125| Name | Type | Mandatory| Description | 1126| --------- | ------------------------------- | ---- | ---------------------------- | 1127| storeId | string | Yes | Name of the RDB store.| 1128| predicates | [relationalStore.RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Predicates for matching the data to share.| 1129| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1130| columns | Array<string> | Yes | Columns in which the data is located.| 1131| callback | AsyncCallback<[relationalStore.ResultSet](js-apis-data-relationalStore.md#resultset)> | Yes | Callback used to return the result set of the data to share.| 1132 1133**Error codes** 1134 1135For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1136 1137| ID| Error Message | 1138| -------- | ---------------------------------------------------- | 1139| 202 | Permission verification failed, application which is not a system application uses system API.| 1140| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1141| 801 | Capability not supported.| 1142 1143**Example** 1144 1145```ts 1146import { relationalStore } from '@kit.ArkData'; 1147import { BusinessError } from '@kit.BasicServicesKit'; 1148 1149let participants = new Array<cloudData.sharing.Participant>(); 1150participants.push({ 1151 identity: '000000000', 1152 role: cloudData.sharing.Role.ROLE_INVITER, 1153 state: cloudData.sharing.State.STATE_UNKNOWN, 1154 privilege: { 1155 writable: true, 1156 readable: true, 1157 creatable: false, 1158 deletable: false, 1159 shareable: false 1160 }, 1161 attachInfo: '' 1162}) 1163let sharingResource: string; 1164let predicates = new relationalStore.RdbPredicates('test_table'); 1165predicates.equalTo('data', 'data_test'); 1166cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, ['uuid', 'data'], (err: BusinessError, resultSet) => { 1167 if (err) { 1168 console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); 1169 return; 1170 } 1171 if (!resultSet.goToFirstRow()) { 1172 console.error(`row error`); 1173 return; 1174 } 1175 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 1176 console.info(`sharing resource: ${res}`); 1177 sharingResource = res; 1178}) 1179 1180``` 1181 1182### allocResourceAndShare<sup>11+</sup> 1183 1184allocResourceAndShare(storeId: string, predicates: relationalStore.RdbPredicates, participants: Array<Participant>, callback: AsyncCallback<relationalStore.ResultSet>): void 1185 1186Allocates a shared resource ID based on the data that matches the specified predicates. This API uses an asynchronous callback to return the result. 1187 1188**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1189 1190**Parameters** 1191 1192| Name | Type | Mandatory| Description | 1193| --------- | ------------------------------- | ---- | ---------------------------- | 1194| storeId | string | Yes | Name of the RDB store.| 1195| predicates | [relationalStore.RdbPredicates](js-apis-data-relationalStore.md#rdbpredicates) | Yes | Predicates for matching the data to share.| 1196| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1197| callback | AsyncCallback<[relationalStore.ResultSet](js-apis-data-relationalStore.md#resultset)> | Yes | Callback used to return the result set of the data to share.| 1198 1199**Error codes** 1200 1201For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1202 1203| ID| Error Message | 1204| -------- | ---------------------------------------------------- | 1205| 202 | Permission verification failed, application which is not a system application uses system API.| 1206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1207| 801 | Capability not supported.| 1208 1209**Example** 1210 1211```ts 1212import { relationalStore } from '@kit.ArkData'; 1213import { BusinessError } from '@kit.BasicServicesKit'; 1214 1215let participants = new Array<cloudData.sharing.Participant>(); 1216participants.push({ 1217 identity: '000000000', 1218 role: cloudData.sharing.Role.ROLE_INVITER, 1219 state: cloudData.sharing.State.STATE_UNKNOWN, 1220 privilege: { 1221 writable: true, 1222 readable: true, 1223 creatable: false, 1224 deletable: false, 1225 shareable: false 1226 }, 1227 attachInfo: '' 1228}) 1229let sharingResource: string; 1230let predicates = new relationalStore.RdbPredicates('test_table'); 1231predicates.equalTo('data', 'data_test'); 1232cloudData.sharing.allocResourceAndShare('storeName', predicates, participants, (err: BusinessError, resultSet) => { 1233 if (err) { 1234 console.error(`alloc resource and share failed, code is ${err.code},message is ${err.message}`); 1235 return; 1236 } 1237 if (!resultSet.goToFirstRow()) { 1238 console.error(`row error`); 1239 return; 1240 } 1241 const res = resultSet.getString(resultSet.getColumnIndex(relationalStore.Field.SHARING_RESOURCE_FIELD)); 1242 console.info(`sharing resource: ${res}`); 1243 sharingResource = res; 1244}) 1245 1246``` 1247 1248### share<sup>11+</sup> 1249 1250share(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> 1251 1252Shares data based on the specified shared resource ID and participants. This API uses a promise to return the result. 1253 1254**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1255 1256**Parameters** 1257 1258| Name | Type | Mandatory| Description | 1259| --------- | ------------------------------- | ---- | ---------------------------- | 1260| sharingResource | string | Yes | Shared resource ID.| 1261| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1262 1263**Return value** 1264 1265| Type | Description | 1266| ------------------- | ------------------------- | 1267| Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| 1268 1269**Error codes** 1270 1271For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1272 1273| ID| Error Message | 1274| -------- | ---------------------------------------------------- | 1275| 202 | Permission verification failed, application which is not a system application uses system API.| 1276| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1277| 801 | Capability not supported.| 1278 1279**Example** 1280 1281```ts 1282import { BusinessError } from '@kit.BasicServicesKit'; 1283 1284let participants = new Array<cloudData.sharing.Participant>(); 1285participants.push({ 1286 identity: '000000000', 1287 role: cloudData.sharing.Role.ROLE_INVITER, 1288 state: cloudData.sharing.State.STATE_UNKNOWN, 1289 privilege: { 1290 writable: true, 1291 readable: true, 1292 creatable: false, 1293 deletable: false, 1294 shareable: false 1295 }, 1296 attachInfo: '' 1297}) 1298cloudData.sharing.share('sharing_resource_test', participants).then((result) => { 1299 console.info(`share success, result: ${result}`); 1300}).catch((err: BusinessError) => { 1301 console.error(`share failed, code is ${err.code},message is ${err.message}`); 1302}) 1303 1304``` 1305 1306### share<sup>11+</sup> 1307 1308share(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void 1309 1310Shares data based on the specified shared resource ID and participants. This API uses an asynchronous callback to return the result. 1311 1312**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1313 1314**Parameters** 1315 1316| Name | Type | Mandatory| Description | 1317| --------- | ------------------------------- | ---- | ---------------------------- | 1318| sharingResource | string | Yes | Shared resource ID.| 1319| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1320| callback | AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback used to return the result. | 1321 1322**Error codes** 1323 1324For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1325 1326| ID| Error Message | 1327| -------- | ---------------------------------------------------- | 1328| 202 | Permission verification failed, application which is not a system application uses system API.| 1329| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1330| 801 | Capability not supported.| 1331 1332**Example** 1333 1334```ts 1335import { BusinessError } from '@kit.BasicServicesKit'; 1336 1337let participants = new Array<cloudData.sharing.Participant>(); 1338participants.push({ 1339 identity: '000000000', 1340 role: cloudData.sharing.Role.ROLE_INVITER, 1341 state: cloudData.sharing.State.STATE_UNKNOWN, 1342 privilege: { 1343 writable: true, 1344 readable: true, 1345 creatable: false, 1346 deletable: false, 1347 shareable: false 1348 }, 1349 attachInfo: '' 1350}) 1351cloudData.sharing.share('sharing_resource_test', participants, ((err: BusinessError, result) => { 1352 if (err) { 1353 console.error(`share failed, code is ${err.code},message is ${err.message}`); 1354 return; 1355 } 1356 console.info(`share succeeded, result: ${result}`); 1357})) 1358 1359``` 1360 1361### unshare<sup>11+</sup> 1362 1363unshare(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> 1364 1365Unshares data based on the specified shared resource ID and participants. This API uses a promise to return the result. 1366 1367**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1368 1369**Parameters** 1370 1371| Name | Type | Mandatory| Description | 1372| --------- | ------------------------------- | ---- | ---------------------------- | 1373| sharingResource | string | Yes | Shared resource ID.| 1374| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1375 1376**Return value** 1377 1378| Type | Description | 1379| ------------------- | ------------------------- | 1380| Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| 1381 1382**Error codes** 1383 1384For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1385 1386| ID| Error Message | 1387| -------- | ---------------------------------------------------- | 1388| 202 | Permission verification failed, application which is not a system application uses system API.| 1389| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1390| 801 | Capability not supported.| 1391 1392**Example** 1393 1394```ts 1395import { BusinessError } from '@kit.BasicServicesKit'; 1396 1397let participants = new Array<cloudData.sharing.Participant>(); 1398participants.push({ 1399 identity: '000000000', 1400 role: cloudData.sharing.Role.ROLE_INVITER, 1401 state: cloudData.sharing.State.STATE_UNKNOWN, 1402 privilege: { 1403 writable: true, 1404 readable: true, 1405 creatable: false, 1406 deletable: false, 1407 shareable: false 1408 }, 1409 attachInfo: '' 1410}) 1411cloudData.sharing.unshare('sharing_resource_test', participants).then((result) => { 1412 console.info(`unshare succeeded, result: ${result}`); 1413}).catch((err: BusinessError) => { 1414 console.error(`unshare failed, code is ${err.code},message is ${err.message}`); 1415}) 1416 1417``` 1418 1419### unshare<sup>11+</sup> 1420 1421unshare(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void 1422 1423Unshares data based on the specified shared resource ID and participants. This API uses an asynchronous callback to return the result. 1424 1425**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1426 1427**Parameters** 1428 1429| Name | Type | Mandatory| Description | 1430| --------- | ------------------------------- | ---- | ---------------------------- | 1431| sharingResource | string | Yes | Shared resource ID.| 1432| participants | Array<[Participant](#participant11)> | Yes | Participants of the share.| 1433| callback | AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback used to return the result. | 1434 1435**Error codes** 1436 1437For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1438 1439| ID| Error Message | 1440| -------- | ---------------------------------------------------- | 1441| 202 | Permission verification failed, application which is not a system application uses system API.| 1442| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1443| 801 | Capability not supported.| 1444 1445**Example** 1446 1447```ts 1448import { BusinessError } from '@kit.BasicServicesKit'; 1449 1450let participants = new Array<cloudData.sharing.Participant>(); 1451participants.push({ 1452 identity: '000000000', 1453 role: cloudData.sharing.Role.ROLE_INVITER, 1454 state: cloudData.sharing.State.STATE_UNKNOWN, 1455 privilege: { 1456 writable: true, 1457 readable: true, 1458 creatable: false, 1459 deletable: false, 1460 shareable: false 1461 }, 1462 attachInfo: '' 1463}) 1464cloudData.sharing.unshare('sharing_resource_test', participants, ((err: BusinessError, result) => { 1465 if (err) { 1466 console.error(`unshare failed, code is ${err.code},message is ${err.message}`); 1467 return; 1468 } 1469 console.info(`unshare succeeded, result: ${result}`); 1470})) 1471 1472``` 1473 1474### exit<sup>11+</sup> 1475 1476exit(sharingResource: string): Promise<Result<void>> 1477 1478Exits the share of the specified shared resource. This API uses a promise to return the result. 1479 1480**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1481 1482**Parameters** 1483 1484| Name | Type | Mandatory| Description | 1485| --------- | ------------------------------- | ---- | ---------------------------- | 1486| sharingResource | string | Yes | Shared resource ID.| 1487 1488**Return value** 1489 1490| Type | Description | 1491| ------------------- | ------------------------- | 1492| Promise<[Result](#resultt11)<void>> | Promise used to return the result.| 1493 1494**Error codes** 1495 1496For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1497 1498| ID| Error Message | 1499| -------- | ---------------------------------------------------- | 1500| 202 | Permission verification failed, application which is not a system application uses system API.| 1501| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1502| 801 | Capability not supported.| 1503 1504**Example** 1505 1506```ts 1507import { BusinessError } from '@kit.BasicServicesKit'; 1508 1509cloudData.sharing.exit('sharing_resource_test').then((result) => { 1510 console.info(`exit share success, result: ${result}`); 1511}).catch((err: BusinessError) => { 1512 console.error(`exit share failed, code is ${err.code},message is ${err.message}`); 1513}) 1514 1515``` 1516 1517### exit<sup>11+</sup> 1518 1519exit(sharingResource: string, callback: AsyncCallback<Result<void>>): void 1520 1521Exits the share of the specified shared resource. This API uses an asynchronous callback to return the result. 1522 1523**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1524 1525**Parameters** 1526 1527| Name | Type | Mandatory| Description | 1528| --------- | ------------------------------- | ---- | ---------------------------- | 1529| sharingResource | string | Yes | Shared resource ID.| 1530| callback | AsyncCallback<[Result](#resultt11)<void>> | Yes | Callback used to return the result. | 1531 1532**Error codes** 1533 1534For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1535 1536| ID| Error Message | 1537| -------- | ---------------------------------------------------- | 1538| 202 | Permission verification failed, application which is not a system application uses system API.| 1539| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1540| 801 | Capability not supported.| 1541 1542**Example** 1543 1544```ts 1545import { BusinessError } from '@kit.BasicServicesKit'; 1546 1547cloudData.sharing.exit('sharing_resource_test', ((err: BusinessError, result) => { 1548 if (err) { 1549 console.error(`exit share failed, code is ${err.code},message is ${err.message}`); 1550 return; 1551 } 1552 console.info(`exit share succeeded, result: ${result}`); 1553})) 1554 1555``` 1556 1557### changePrivilege<sup>11+</sup> 1558 1559changePrivilege(sharingResource: string, participants: Array<Participant>): Promise<Result<Array<Result<Participant>>>> 1560 1561Changes the privilege on the shared data. This API uses a promise to return the result. 1562 1563**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1564 1565**Parameters** 1566 1567| Name | Type | Mandatory| Description | 1568| --------- | ------------------------------- | ---- | ---------------------------- | 1569| sharingResource | string | Yes | Shared resource ID.| 1570| participants | Array<[Participant](#participant11)> | Yes | Participants with new privilege.| 1571 1572**Return value** 1573 1574| Type | Description | 1575| ------------------- | ------------------------- | 1576| Promise<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Promise used to return the result.| 1577 1578**Error codes** 1579 1580For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1581 1582| ID| Error Message | 1583| -------- | ---------------------------------------------------- | 1584| 202 | Permission verification failed, application which is not a system application uses system API.| 1585| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1586| 801 | Capability not supported.| 1587 1588**Example** 1589 1590```ts 1591import { BusinessError } from '@kit.BasicServicesKit'; 1592 1593let participants = new Array<cloudData.sharing.Participant>(); 1594participants.push({ 1595 identity: '000000000', 1596 role: cloudData.sharing.Role.ROLE_INVITER, 1597 state: cloudData.sharing.State.STATE_UNKNOWN, 1598 privilege: { 1599 writable: true, 1600 readable: true, 1601 creatable: false, 1602 deletable: false, 1603 shareable: false 1604 }, 1605 attachInfo: '' 1606}) 1607 1608cloudData.sharing.changePrivilege('sharing_resource_test', participants).then((result) => { 1609 console.info(`change privilege succeeded, result: ${result}`); 1610}).catch((err: BusinessError) => { 1611 console.error(`change privilege failed, code is ${err.code},message is ${err.message}`); 1612}) 1613 1614``` 1615 1616### changePrivilege<sup>11+</sup> 1617 1618changePrivilege(sharingResource: string, participants: Array<Participant>, callback: AsyncCallback<Result<Array<Result<Participant>>>>): void 1619 1620Changes the privilege on the shared data. This API uses an asynchronous callback to return the result. 1621 1622**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1623 1624**Parameters** 1625 1626| Name | Type | Mandatory| Description | 1627| --------- | ------------------------------- | ---- | ---------------------------- | 1628| sharingResource | string | Yes | Shared resource ID.| 1629| participants | Array<[Participant](#participant11)> | Yes | Participants with new privilege.| 1630| callback | callback: AsyncCallback<[Result](#resultt11)<Array<[Result](#resultt11)<[Participant](#participant11)>>>> | Yes | Callback used to return the result. | 1631 1632**Error codes** 1633 1634For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1635 1636| ID| Error Message | 1637| -------- | ---------------------------------------------------- | 1638| 202 | Permission verification failed, application which is not a system application uses system API.| 1639| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1640| 801 | Capability not supported.| 1641 1642**Example** 1643 1644```ts 1645import { BusinessError } from '@kit.BasicServicesKit'; 1646 1647let participants = new Array<cloudData.sharing.Participant>(); 1648participants.push({ 1649 identity: '000000000', 1650 role: cloudData.sharing.Role.ROLE_INVITER, 1651 state: cloudData.sharing.State.STATE_UNKNOWN, 1652 privilege: { 1653 writable: true, 1654 readable: true, 1655 creatable: false, 1656 deletable: false, 1657 shareable: false 1658 }, 1659 attachInfo: '' 1660}) 1661 1662cloudData.sharing.changePrivilege('sharing_resource_test', participants, ((err: BusinessError, result) => { 1663 if (err) { 1664 console.error(`change privilege failed, code is ${err.code},message is ${err.message}`); 1665 return; 1666 } 1667 console.info(`change privilege succeeded, result: ${result}`); 1668})) 1669 1670``` 1671 1672### queryParticipants<sup>11+</sup> 1673 1674queryParticipants(sharingResource: string): Promise<Result<Array<Participant>>> 1675 1676Queries the participants of the specified shared data. This API uses a promise to return the result. 1677 1678**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1679 1680**Parameters** 1681 1682| Name | Type | Mandatory| Description | 1683| --------- | ------------------------------- | ---- | ---------------------------- | 1684| sharingResource | string | Yes | Shared resource ID.| 1685 1686**Return value** 1687 1688| Type | Description | 1689| ------------------- | ------------------------- | 1690| Promise<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Promise used to return the participants obtained.| 1691 1692**Error codes** 1693 1694For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1695 1696| ID| Error Message | 1697| -------- | ---------------------------------------------------- | 1698| 202 | Permission verification failed, application which is not a system application uses system API.| 1699| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1700| 801 | Capability not supported.| 1701 1702**Example** 1703 1704```ts 1705import { BusinessError } from '@kit.BasicServicesKit'; 1706 1707cloudData.sharing.queryParticipants('sharing_resource_test').then((result) => { 1708 console.info(`query participants succeeded, result: ${result}`); 1709}).catch((err: BusinessError) => { 1710 console.error(`query participants failed, code is ${err.code},message is ${err.message}`); 1711}) 1712 1713``` 1714 1715### queryParticipants<sup>11+</sup> 1716 1717queryParticipants(sharingResource: string, callback: AsyncCallback<Result<Array<Participant>>>): void 1718 1719Queries the participants of the specified shared data. This API uses an asynchronous callback to return the result. 1720 1721**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1722 1723**Parameters** 1724 1725| Name | Type | Mandatory| Description | 1726| --------- | ------------------------------- | ---- | ---------------------------- | 1727| sharingResource | string | Yes | Shared resource ID.| 1728| callback | AsyncCallback<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Yes | Callback used to return the participants obtained.| 1729 1730**Error codes** 1731 1732For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1733 1734| ID| Error Message | 1735| -------- | ---------------------------------------------------- | 1736| 202 | Permission verification failed, application which is not a system application uses system API.| 1737| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1738| 801 | Capability not supported.| 1739 1740**Example** 1741 1742```ts 1743import { BusinessError } from '@kit.BasicServicesKit'; 1744 1745cloudData.sharing.queryParticipants('sharing_resource_test', ((err: BusinessError, result) => { 1746 if (err) { 1747 console.error(`query participants failed, code is ${err.code},message is ${err.message}`); 1748 return; 1749 } 1750 console.info(`query participants succeeded, result: ${result}`); 1751})) 1752 1753``` 1754 1755### queryParticipantsByInvitation<sup>11+</sup> 1756 1757queryParticipantsByInvitation(invitationCode: string): Promise<Result<Array<Participant>>> 1758 1759Queries the participants based on the sharing invitation code. This API uses a promise to return the result. 1760 1761**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1762 1763**Parameters** 1764 1765| Name | Type | Mandatory| Description | 1766| --------- | ------------------------------- | ---- | ---------------------------- | 1767| invitationCode | string | Yes | Invitation code of the share.| 1768 1769**Return value** 1770 1771| Type | Description | 1772| ------------------- | ------------------------- | 1773| Promise<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Promise used to return the participants obtained.| 1774 1775**Error codes** 1776 1777For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1778 1779| ID| Error Message | 1780| -------- | ---------------------------------------------------- | 1781| 202 | Permission verification failed, application which is not a system application uses system API.| 1782| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1783| 801 | Capability not supported.| 1784 1785**Example** 1786 1787```ts 1788import { BusinessError } from '@kit.BasicServicesKit'; 1789 1790cloudData.sharing.queryParticipantsByInvitation('sharing_invitation_code_test').then((result) => { 1791 console.info(`query participants by invitation succeeded, result: ${result}`); 1792}).catch((err: BusinessError) => { 1793 console.error(`query participants by invitation failed, code is ${err.code},message is ${err.message}`); 1794}) 1795 1796``` 1797 1798### queryParticipantsByInvitation<sup>11+</sup> 1799 1800queryParticipantsByInvitation(invitationCode: string, callback: AsyncCallback<Result<Array<Participant>>>): void 1801 1802Queries the participants based on the sharing invitation code. This API uses an asynchronous callback to return the result. 1803 1804**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1805 1806**Parameters** 1807 1808| Name | Type | Mandatory| Description | 1809| --------- | ------------------------------- | ---- | ---------------------------- | 1810| invitationCode | string | Yes | Invitation code of the share.| 1811| callback | AsyncCallback<[Result](#resultt11)<Array<[Participant](#participant11)>>> | Yes | Callback used to return the participants obtained.| 1812 1813**Error codes** 1814 1815For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1816 1817| ID| Error Message | 1818| -------- | ---------------------------------------------------- | 1819| 202 | Permission verification failed, application which is not a system application uses system API.| 1820| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1821| 801 | Capability not supported.| 1822 1823**Example** 1824 1825```ts 1826import { BusinessError } from '@kit.BasicServicesKit'; 1827 1828cloudData.sharing.queryParticipantsByInvitation('sharing_invitation_code_test', ((err: BusinessError, result) => { 1829 if (err) { 1830 console.error(`query participants by invitation failed, code is ${err.code},message is ${err.message}`); 1831 return; 1832 } 1833 console.info(`query participants by invitation succeeded, result: ${result}`); 1834})) 1835 1836``` 1837 1838### confirmInvitation<sup>11+</sup> 1839 1840confirmInvitation(invitationCode: string, state: State): Promise<Result<string>> 1841 1842Confirms the invitation based on the sharing invitation code and obtains the shared resource ID. This API uses a promise to return the result. 1843 1844**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1845 1846**Parameters** 1847 1848| Name | Type | Mandatory| Description | 1849| --------- | ------------------------------- | ---- | ---------------------------- | 1850| invitationCode | string | Yes | Invitation code of the share.| 1851| state | [State](#state11) | Yes | Confirmation state.| 1852 1853**Return value** 1854 1855| Type | Description | 1856| ------------------- | ------------------------- | 1857| Promise<[Result](#resultt11)<string>> | Promise used to return the result.| 1858 1859**Error codes** 1860 1861For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1862 1863| ID| Error Message | 1864| -------- | ---------------------------------------------------- | 1865| 202 | Permission verification failed, application which is not a system application uses system API.| 1866| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1867| 801 | Capability not supported.| 1868 1869**Example** 1870 1871```ts 1872import { BusinessError } from '@kit.BasicServicesKit'; 1873 1874let shareResource: string | undefined; 1875cloudData.sharing.confirmInvitation('sharing_invitation_code_test', cloudData.sharing.State.STATE_ACCEPTED).then((result: cloudData.sharing.Result<string>) => { 1876 console.info(`confirm invitation succeeded, result: ${result}`); 1877 shareResource = result.value; 1878}).catch((err: BusinessError) => { 1879 console.error(`confirm invitation failed, code is ${err.code},message is ${err.message}`); 1880}) 1881 1882``` 1883 1884### confirmInvitation<sup>11+</sup> 1885 1886confirmInvitation(invitationCode: string, state: State, callback: AsyncCallback<Result<string>>): void 1887 1888Confirms the invitation based on the sharing invitation code and obtains the shared resource ID. This API uses an asynchronous callback to return the result. 1889 1890**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1891 1892**Parameters** 1893 1894| Name | Type | Mandatory| Description | 1895| --------- | ------------------------------- | ---- | ---------------------------- | 1896| invitationCode | string | Yes | Invitation code of the share.| 1897| state | [State](#state11) | Yes | Confirmation state.| 1898| callback | AsyncCallback<[Result](#resultt11)<string>> | Yes | Callback used to return the result. | 1899 1900**Error codes** 1901 1902For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1903 1904| ID| Error Message | 1905| -------- | ---------------------------------------------------- | 1906| 202 | Permission verification failed, application which is not a system application uses system API.| 1907| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1908| 801 | Capability not supported.| 1909 1910**Example** 1911 1912```ts 1913import { BusinessError } from '@kit.BasicServicesKit'; 1914 1915let shareResource: string; 1916cloudData.sharing.confirmInvitation('sharing_invitation_code_test', cloudData.sharing.State.STATE_ACCEPTED, ((err: BusinessError, result) => { 1917 if (err) { 1918 console.error(`confirm invitation failed, code is ${err.code},message is ${err.message}`); 1919 return; 1920 } 1921 console.info(`confirm invitation succeeded, result: ${result}`); 1922 shareResource = result.value; 1923})) 1924 1925``` 1926 1927### changeConfirmation<sup>11+</sup> 1928 1929changeConfirmation(sharingResource: string, state: State): Promise<Result<void>> 1930 1931Changes the invitation confirmation state based on the shared resource ID. This API uses a promise to return the result. 1932 1933**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1934 1935**Parameters** 1936 1937| Name | Type | Mandatory| Description | 1938| --------- | ------------------------------- | ---- | ---------------------------- | 1939| sharingResource | string | Yes | Shared resource ID.| 1940| state | [State](#state11) | Yes | New confirmation state of the invitation.| 1941 1942**Return value** 1943 1944| Type | Description | 1945| ------------------- | ------------------------- | 1946| Promise<[Result](#resultt11)<void>> | Promise used to return the result.| 1947 1948**Error codes** 1949 1950For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1951 1952| ID| Error Message | 1953| -------- | ---------------------------------------------------- | 1954| 202 | Permission verification failed, application which is not a system application uses system API.| 1955| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1956| 801 | Capability not supported.| 1957 1958**Example** 1959 1960```ts 1961import { BusinessError } from '@kit.BasicServicesKit'; 1962 1963cloudData.sharing.changeConfirmation('sharing_resource_test', cloudData.sharing.State.STATE_REJECTED).then((result) => { 1964 console.info(`change confirmation succeeded, result: ${result}`); 1965}).catch((err: BusinessError) => { 1966 console.error(`change confirmation failed, code is ${err.code},message is ${err.message}`); 1967}) 1968 1969``` 1970 1971### changeConfirmation<sup>11+</sup> 1972 1973changeConfirmation(sharingResource: string, state: State, callback: AsyncCallback<Result<void>>): void; 1974 1975Changes the invitation confirmation state based on the shared resource ID. This API uses an asynchronous callback to return the result. 1976 1977**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client 1978 1979**Parameters** 1980 1981| Name | Type | Mandatory| Description | 1982| --------- | ------------------------------- | ---- | ---------------------------- | 1983| sharingResource | string | Yes | Shared resource ID.| 1984| state | [State](#state11) | Yes | New confirmation state of the invitation.| 1985| callback | AsyncCallback<[Result](#resultt11)<void>> | Yes | Callback used to return the result. | 1986 1987**Error codes** 1988 1989For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1990 1991| ID| Error Message | 1992| -------- | ---------------------------------------------------- | 1993| 202 | Permission verification failed, application which is not a system application uses system API.| 1994| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.| 1995| 801 | Capability not supported.| 1996 1997**Example** 1998 1999```ts 2000import { BusinessError } from '@kit.BasicServicesKit'; 2001 2002cloudData.sharing.changeConfirmation('sharing_resource_test', cloudData.sharing.State.STATE_REJECTED, ((err: BusinessError, result) => { 2003 if (err) { 2004 console.error(`change confirmation failed, code is ${err.code},message is ${err.message}`); 2005 return; 2006 } 2007 console.info(`change confirmation succeeded, result: ${result}`); 2008})) 2009 2010``` 2011<!--no_check--> 2012