Automate Sage X3 Cloud Integration Tasks from PowerShell
The CData ADO.NET Provider for Sage X3 Cloud is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Sage X3 Cloud.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Sage X3 Cloud; this tutorial shows how to use the Provider to retrieve Sage X3 Cloud data.
Once you have acquired the necessary connection properties, accessing Sage X3 Cloud data in PowerShell can be enabled in three steps.
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.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Sage X3 Cloud\lib\System.Data.CData.SageX3Cloud.dll") -
Connect to Sage X3 Cloud:
$conn= New-Object System.Data.CData.SageX3Cloud.SageX3CloudConnection("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;") $conn.Open() -
Instantiate the SageX3CloudDataAdapter, execute an SQL query, and output the results:
$sql="SELECT BPCNUM, BPCNAM from BPCUSTOMER" $da= New-Object System.Data.CData.SageX3Cloud.SageX3CloudDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.bpcnum $_.bpcnam }