The connection is identified using
syncId, a
resource ID returned by
Sync.connect. While optional, this should generally be specified explicitly. (If there is only one synchronization session active, the resource ID can be calculated implicitly.)
Once the connection is closed, additional requests to the synchronization service cannot occur until creating another connection.
The action returns undefined.
The action throws an exception if any of its arguments are not specified in a valid form, or if:
- The synchronization connection ID is not valid.
- There is a network error while disconnecting from the synchronization service.
let syncId;
// connect to CSWeb, supplying the username and password
CS.Sync.connectAsync({
connection: {
url: "https://example.org/csweb/api",
username: "jackw",
password: "MyPa$$w0rd!"
}
})
.then(id => {
// store the resource ID that identifies this synchronization connection
syncId = id;
// send a message to the server
return CS.Sync.sendMessageAsync({
syncId: syncId,
name: "Demonstrating Sync.sendMessage at: " + new Date().toString()
});
})
.then(response => {
print("Successfully sent a message and received: " + JSON.stringify(response));
})
.finally(() => {
// close the synchronization connection
if( syncId != undefined ) {
return CS.Sync.disconnectAsync({
syncId: syncId
});
}
})
.catch(error => {
print("Error syncing: " + error);
})