Replicate Multiple USPS Accounts

Ready to get started?

Learn more or sign up for a free trial:

CData Sync



Replicate multiple USPS accounts to one or many databases.

CData Sync for USPS 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 USPS connections. In this article we show how to use the CLI to replicate multiple USPS accounts.

Configure USPS Connections

You can save connection and email notification settings in an XML configuration file. To replicate multiple USPS accounts, use multiple configuration files. Below is an example configuration to replicate USPS to SQLite:

Windows

<?xml version="1.0" encoding="UTF-8" ?> <CDataSync> <DatabaseType>SQLite</DatabaseType> <DatabaseProvider>System.Data.SQLite</DatabaseProvider> <ConnectionString>PostageProvider=ENDICIA; RequestId=12345; Password='abcdefghijklmnopqr'; AccountNumber='12A3B4C'</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>PostageProvider=ENDICIA; RequestId=12345; Password='abcdefghijklmnopqr'; AccountNumber='12A3B4C'</ConnectionString> <ReplicateAll>False</ReplicateAll> <NotificationUserName></NotificationUserName> <DatabaseConnectionString>Data Source=C:\my.db</DatabaseConnectionString> </CDataSync>

To authenticate with USPS, set the following connection properties.

  • PostageProvider: The postage provider to use to process requests. Available options are ENDICIA and STAMPS. If unspecified, this property will default to ENDICIA.
  • UseSandbox: This controls whether live or test requests are sent to the production or sandbox servers. If set to true, the Password, AccountNumber, and StampsUserId properties are ignored.
  • StampsUserId: This value is used for logging into authentication to the Stamps servers. This value is not applicable for Endicia and is optional if UseSandbox is true.
  • Password: This value is used for logging into Endicia and Stamps servers. If the postage provider is Endicia, this will be the pass phrase associated with your postage account. It is optional if UseSandbox is true.
  • AccountNumber: The shipper's account number. It is optional if UseSandbox is true.
  • PrintLabelLocation: This property is required to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

The Cache Database

Many of the useful task available from USPS require a lot of data. To ensure this data is easy to input and recall later, utilize a cache database to make requests. Set the cache connection properties in order to use the cache:

  • CacheLocation: The path to the cache location, for which a connection will be configured with the default cache provider. For example, C:/users/username/documents/uspscache

As an alternative to CacheLocation, set the combination of CacheConnection and CacheProvider to configure a cache connection using a provider separate from the default.

Configure Queries for Each USPS 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 USPS API. The statement below caches and incrementally updates a table of USPS data:

REPLICATE Senders;

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 USPS accounts into the same database:

You can use a different table prefix in the REPLICATE SELECT statement:

REPLICATE PROD_Senders SELECT * FROM Senders

Alternatively, you can use a different schema:

REPLICATE PROD.Senders SELECT * FROM Senders

Run Sync

After you have configured the connection strings and replication queries, you can run Sync with the following command-line options:

Windows

USPSSync.exe -g MyProductionUSPSConfig.xml -f MyProductionUSPSSync.sql

Java

java -Xbootclasspath/p:c:\sqlitejdbc.jar -jar USPSSync.jar -g MyProductionUSPSConfig.xml -f MyProductionUSPSSync.sql