Cmdlets for Acumatica

Build 25.0.9434

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our Acumatica Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Connecting to Acumatica

In order to connect to the Acumatica data source, you must specify the following connection properties.

  • URL: (Required) The base URL for the Acumatica ERP instance. For example: https://domain.acumatica.com/.
  • Schema: (Optional) There are two schemas that contain different data. The default one is REST, which uses the Acumatica REST Contract-Based API, and the OData schema, which uses the Acumatica OData API. The OData schema is used to query Acumatica Generic Inquiries.
  • Company: (Partially required) Set this to the name of your company or tenant. It is required if Schema is set to OData.
  • EndpointVersion: (Optional) The version of the Web Services endpoint. For example: 24.200.001. This applies only to the REST schema.
  • EndpointName: (Optional) The name of the Web Services endpoint. For example: Default. This applies only to the REST schema.

To find out the EndpointVersion and EndpointName for your Acumatica instance, log into Acumatica in a web browser, and then navigate to the Web Service Endpoints page. If necessary, navigate to this page by editing the web browser URL and replacing ScreenId=00000000 (the homepage) with ScreenId=SM207060. If you are redirected back to the homepage, this means your user does not have the necessary permissions to access web services. Under Endpoints properties get the Endpoint Name and Endpoint Version.

Exposing Generic Inquiries

The cmdlet is capable of discovering generic inquiry data as tables and views. However, you must first extend the Web Services Endpoint to expose them.

The process for exposing generic inquiries is different depending on the schema specified in the Schema connection property.

REST Schema

Generic Inquiries are not exposed via REST by default. To expose them:

  1. Navigate in the Acumatica UI to Integration > Show All > Web Service Endpoints.
  2. Click the "Default" endpoint with the most recent Endpoint Version.
  3. From the available action buttons (in the button bar below the endpoint name at the top of the page), click EXTEND ENDPOINT.
    • You may have to find this action in the full action list, which you can view by clicking the "..." button.
  4. Use Endpoint Name to name the extended endpoint and Endpoint Version to specify the endpoint version you want it to have, then click OK.
  5. On the page for your new extended endpoint, click the + Insert button (above the ENDPOINT tree structure).
  6. Create an entity definition for a new custom object as follows.
    • Name the object in the Object Name field.
    • Leave the Object Type field set to the default -- Top-Level.
    • In the Screen Name field, click the magnifying glass icon to search for the screen associated with your generic inquiry. Select the screen matching the Site Map Title field of your generic inquiry.
      • Ensure that the autopopulated Screen ID field's value matches that of your generic inquiry.
    • Click OK.
  7. Create a new "Results" entity under your custom object as follows:
    • Select the newly created object in the ENDPOINT tree structure, then click the + Insert button.
    • Set Field Name to "Result".
    • Specify a name for this object in Object Name.
    • Set Object Type to Detail.
    • Click OK.
  8. In the ENDPOINT tree structure, expand the node for your custom object, select the new Results object you just created, then click FIELDS > POPULATE.
  9. In the Populate Field window's Object field, select "Result" (the object you just created).
  10. Select the check box for each field you want to expose from the general inquiry, then click OK.
  11. To see the exposed general inquiry in your table list, set EndpointName to the name of your extended endpoint and set InquiryTables to the name of your top-level custom object from step 6 above.

OData Schema

Generic Inquiries are not exposed via OData by default. To expose them, navigate in the Acumatica UI to Customization > Profiles > Generic Inquiry and select the Expose via OData checkbox.

Authenticating to Acumatica

There are two authentication methods available for connecting to Acumatica data source, Basic and OAuth.

User Credentials

Set the AuthScheme to Basic and set the User and Password to your login credentials.

OAuth

OAuth requires the authenticating user to interact with Acumatica using the browser, so all OAuth flows require a custom OAuth application. Also, for all flows, set AuthScheme to OAuth. The following sections assume that you have done so.

Desktop Applications

CData provides an embedded OAuth application that simplifies OAuth desktop Authentication. Alternatively, you can create a custom OAuth application. See Creating a Custom OAuth App for information about creating custom applications and reasons for doing so.

For authentication, the only difference between the two methods is that you must set two additional connection properties when using custom OAuth applications.

After setting the following connection properties, you are ready to connect:

  • OAuthClientId: Set this to the client Id in your application settings.
  • OAuthClientSecret: Set this to the client secret in your application settings.
  • CallbackURL: Set this to the Redirect URL in your application settings.

When you connect the cmdlet opens the OAuth endpoint in your default browser. Log in and grant permissions to the application.

Web Applications

When connecting via a Web application, you need to create and register a custom OAuth application with Acumatica. See Creating a Custom OAuth App for more information about custom applications. You can then use the cmdlet to acquire and manage the OAuth token values.

Get an OAuth Access Token

Set the following connection properties to obtain the OAuthAccessToken:

Then call stored procedures to complete the OAuth exchange:

  1. Call the GetOAuthAuthorizationURL stored procedure. Set the CallbackURL input to the callback URL you specified in your application settings. If necessary, set the Scope parameter to request custom permissions.

    The stored procedure returns the URL to the OAuth endpoint.

  2. Open the URL, log in, and authorize the application. You are redirected back to the callback URL.
  3. Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the "code" parameter in the query string of the callback URL. If necessary, set the Scope parameter to request custom permissions.

Once you have obtained the access and refresh tokens, you can connect to data and refresh the OAuth access token either automatically or manually.

Automatic Refresh of the OAuth Access Token

To have the driver automatically refresh the OAuth access token, set the following for the first data connection:

On subsequent data connections, the values for OAuthAccessToken and OAuthRefreshToken are taken from OAuthSettingsLocation.

Manual Refresh of the OAuth Access Token

The only value needed to manually refresh the OAuth access token when connecting to data is the OAuth refresh token.

Use the RefreshOAuthAccessToken stored procedure to manually refresh the OAuthAccessToken after the ExpiresIn parameter value returned by GetOAuthAccessToken has elapsed, then set the following connection properties:

  • OAuthClientId: Set this to the client Id in your application settings.
  • OAuthClientSecret: Set this to the client secret in your application settings.

Then call RefreshOAuthAccessToken with OAuthRefreshToken set to the OAuth refresh token returned by GetOAuthAccessToken. After retrieving the new tokens, open a new connection by setting the OAuthAccessToken property to the value returned by RefreshOAuthAccessToken.

Finally, store the OAuth refresh token so that you can use it to manually refresh the OAuth access token after it has expired.

Creating a Connection Object

You can then use the Connect-Acumatica cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-Acumatica -OAuthClientId 'MyApplicationId' -OAuthClientSecret 'MySecretKey' -OAuthCallbackURL 'http://localhost:33333'

Retrieving Data

The Select-Acumatica cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-Acumatica -Connection $conn -Table "Events" -Columns @("Id, location_displayName") -Where "Id='Jq74mCczmFXk1tC10GB'"
The Invoke-Acumatica cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-Acumatica -Connection $conn -Table Events -Where "Id = 'Jq74mCczmFXk1tC10GB'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myEventsData.csv -NoTypeInformation

You will notice that we piped the results from Select-Acumatica into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-Acumatica -OAuthClientId 'MyApplicationId' -OAuthClientSecret 'MySecretKey' -OAuthCallbackURL 'http://localhost:33333'
PS C:\> $row = Select-Acumatica -Connection $conn -Table "Events" -Columns (Id, location_displayName) -Where "Id = 'Jq74mCczmFXk1tC10GB'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "Events",
  "Columns":  [

  ],
  "Id":  "MyId",
  "location_displayName":  "Mylocation_displayName"
} 

Deleting Data

The following line deletes any records that match the criteria:

Select-Acumatica -Connection $conn -Table Events -Where "Id = 'Jq74mCczmFXk1tC10GB'" | Remove-Acumatica

Modifying Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Acumatica, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyEventsUpdates.csv | %{
  $record = Select-Acumatica -Connection $conn -Table Events -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-Acumatica -Connection $conn -Table Events -Columns @("Id","location_displayName") -Values @($_.Id, $_.location_displayName) -Where "Id  = `'$_.Id`'"
  }else{
    Add-Acumatica -Connection $conn -Table Events -Columns @("Id","location_displayName") -Values @($_.Id, $_.location_displayName)
  }
}

Copyright (c) 2025 CData Software, Inc. - All rights reserved.
Build 25.0.9434