The argument
connection is a
synchronization connection string, generally a server URL or text identifying the service. The connection string contains information about the resource that CSPro will connect to, and any additional parameters (such as a username and password). Connection strings can be specified as a single string or as an object (with the rules for each
described here). Details about properties specific to each synchronization service are available on the documentation describing each of the services that CSPro supports:
| Synchronization Service | Example Connection String |
| Bluetooth | "Bluetooth" |
| CSWeb | "https://example.org/csweb/api" |
| Dropbox | "Dropbox" |
| FTP | "ftpes://example.org" |
| Local Files | "file:///C:/surveys/ftp-server" |
This action is similar to the CSPro
logic function
syncconnect. When using actions, multiple synchronization sessions can be created, whereas using CSPro logic, there is only one session per call to
syncconnect.
The action returns a numeric
resource ID that is used to identify this synchronization session in calls to future
Sync actions.
The action throws an exception if any of its arguments are not specified in a valid form, or if:
- There is a network error while connecting to the synchronization service.
- The service rejected the connection (e.g., the user does not have a valid password or permissions).
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);
})