Replicate Multiple Sage X3 Cloud Accounts via the CData Sync CLI
CData Sync for Sage X3 Cloud is a stand-alone application that provides solutions for a variety of replication scenarios such as replicating sandbox and production instances into your database. Both Sync for Windows and Sync for Java include a command-line interface (CLI) that makes it easy to manage multiple Sage X3 Cloud connections. In this article we show how to use the CLI to replicate multiple Sage X3 Cloud accounts.
Configure Sage X3 Cloud Connections
You can save connection and email notification settings in an XML configuration file. To replicate multiple Sage X3 Cloud accounts, use multiple configuration files. Below is an example configuration to replicate Sage X3 Cloud to SQLite:
Windows
<?xml version="1.0" encoding="UTF-8" ?>
<CDataSync>
<DatabaseType>SQLite</DatabaseType>
<DatabaseProvider>System.Data.SQLite</DatabaseProvider>
<ConnectionString>AuthScheme=OAuth;URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;</ConnectionString>
<ReplicateAll>False</ReplicateAll>
<NotificationUserName></NotificationUserName>
<DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString>
<TaskSchedulerStartTime>09:51</TaskSchedulerStartTime>
<TaskSchedulerInterval>Never</TaskSchedulerInterval>
</CDataSync>
Java
<?xml version="1.0" encoding="UTF-8" ?>
<CDataSync>
<DatabaseType>SQLite</DatabaseType>
<DatabaseProvider>org.sqlite.JDBC</DatabaseProvider>
<ConnectionString>AuthScheme=OAuth;URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;</ConnectionString>
<ReplicateAll>False</ReplicateAll>
<NotificationUserName></NotificationUserName>
<DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString>
</CDataSync>
Sage X3 Cloud uses the OAuth 2.0 Client Credentials flow, and an X-API-Key is also required for API access. Set AuthScheme to OAuth and specify the following connection properties:
- URL: The base URL of your Sage X3 Cloud instance.
- OAuthAccessTokenUrl: The OAuth token endpoint (e.g., https://your-auth-domain/oauth/token).
- OAuthClientId: Your OAuth application client ID.
- OAuthClientSecret: Your OAuth application client secret.
- Audience: The API audience value for the token request.
- XAPIKey: The X-API-Key provided by your Sage X3 Cloud administrator.
- Folder: The Sage X3 folder name (e.g., SEED). This folder is used as the default schema.
- Folders (optional): A comma-separated list of Sage X3 folders (e.g., SEED,PERF). Each folder is exposed as a separate schema, so you can query across folders with the Schema.Table syntax.
The driver obtains an access token with the Client Credentials flow and sends it with the X-API-Key on every API request. With InitiateOAuth set to GETANDREFRESH (the default), the driver acquires and refreshes the token automatically.
Configure Queries for Each Sage X3 Cloud Instance
Sync enables you to control replication with standard SQL. The REPLICATE statement is a high-level command that caches and maintains a table in your database. You can define any SELECT query supported by the Sage X3 Cloud API. The statement below caches and incrementally updates a table of Sage X3 Cloud data:
REPLICATE BPCUSTOMER;
You can specify a file containing the replication queries you want to use to update a particular database. Separate replication statements with semicolons. The following options are useful if you are replicating multiple Sage X3 Cloud accounts into the same database:
You can use a different table prefix in the REPLICATE SELECT statement:
REPLICATE PROD_BPCUSTOMER SELECT * FROM BPCUSTOMER
Alternatively, you can use a different schema:
REPLICATE PROD.BPCUSTOMER SELECT * FROM BPCUSTOMER
Run Sync
After you have configured the connection strings and replication queries, you can run Sync with the following command-line options:
Windows
SageX3CloudSync.exe -g MyProductionSageX3CloudConfig.xml -f MyProductionSageX3CloudSync.sql
Java
java -Xbootclasspath/p:c:\sqlitejdbc.jar -jar SageX3CloudSync.jar -g MyProductionSageX3CloudConfig.xml -f MyProductionSageX3CloudSync.sql