PowerShell Scripting to Replicate Cvent Data to MySQL



Write a simple PowerShell script to replicate Cvent data to a MySQL database.

The CData Cmdlets for Cvent offer live access to Cvent data from within PowerShell. Using PowerShell scripts, you can easily automate regular tasks like data replication. This article will walk through using the CData Cmdlets for Cvent and the CData Cmdlets for MySQL in PowerShell to replicate Cvent data to a MySQL database.

After obtaining the needed connection properties, accessing Cvent data in PowerShell and preparing for replication consists of four basic steps.

Before you can authenticate to Cvent, you must create a workspace and an OAuth application.

Creating a Workspace

To create a workspace:

  1. Sign into Cvent and navigate to App Switcher (the blue button in the upper right corner of the page) >> Admin.
  2. In the Admin menu, navigate to Integrations >> REST API.
  3. A new tab launches for Developer Management. Click on Manage API Access in the new tab.
  4. Create a Workspace and name it. Select the scopes you would like your developers to have access to. Scopes control what data domains the developer can access.
    • Choose All to allow developers to choose any scope, and any future scopes added to the REST API.
    • Choose Custom to limit the scopes developers can choose for their OAuth apps to selected scopes. To access all tables exposed by the driver, you need to set the following scopes:
      event/attendees:readevent/attendees:writeevent/contacts:read
      event/contacts:writeevent/custom-fields:readevent/custom-fields:write
      event/events:readevent/events:writeevent/sessions:delete
      event/sessions:readevent/sessions:writeevent/speakers:delete
      event/speakers:readevent/speakers:writebudget/budget-items:read
      budget/budget-items:writeexhibitor/exhibitors:readexhibitor/exhibitors:write
      survey/surveys:readsurvey/surveys:write

Creating an OAuth Application

After you have set up a Workspace and invited them, developers can sign up and create a custom OAuth app. See the Creating a Custom OAuth Application section in the Help documentation for more information.

Connecting to Cvent

After creating an OAuth application, set the following connection properties to connect to Cvent:

  • InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
  • OAuthClientId: The Client ID associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.
  • OAuthClientSecret: The Client secret associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.

Collecting Cvent Data

  1. Install the module:

    Install-Module CventCmdlets
  2. Connect to Cvent:

    $cvent = Connect-Cvent -OAuthClientId $OAuthClientId -OAuthClientSecret $OAuthClientSecret
  3. Retrieve the data from a specific resource:

    $data = Select-Cvent -Connection $cvent -Table "Events"

    You can also use the Invoke-Cvent cmdlet to execute pure SQL-92 statements:

    $data = Invoke-Cvent -Connection $cvent -Query 'SELECT * FROM Events WHERE Virtual = @Virtual' -Params @{'@Virtual'='true'}
  4. Save a list of the column names from the returned data.

    $columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name

Inserting Cvent Data into the MySQL Database

With the data and column names collected, you are ready to replicate the data into a MySQL database.

  1. Install the module:

    Install-Module MySQLCmdlets
  2. Connect to MySQL, using the server address and port of the MySQL server, valid user credentials, and a specific database with the table in which the data will be replicated:

    $mysql = Connect-MySQL -User $User -Password $Password -Database $Database -Server $Server -Port $Port
  3. Loop through the Cvent data, store the values, and use the Add-MySQL cmdlet to insert the data into the MySQL database, one row at a time. In this example, the table will need to have the same name as the Cvent resource (Events) and to exist in the database.

    $data | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "Events" -Columns $columns -Values $values }

You have now replicated your Cvent data to a MySQL database. This gives you freedom to work with Cvent data in the same way that you work with other MySQL tables, whether that is performing analytics, building reports, or other business functions.

Notes

  • Once you have connected to Cvent and MySQL in PowerShell, you can pipe command results to perform the replication in a single line:

    Select-Cvent -Connection $cvent -Table "Events" | % { $row = $_ $values = @() $columns | % { $col = $_ $values += $row.$($col) } Add-MySQL -Connection $mysql -Table "Events" -Columns $columns -Values $values }
  • If you wish to replicate the Cvent data to another database using another PowerShell module, you will want to exclude the Columns, Connection, and Table columns from the data returned by the Select-Cvent cmdlet since those columns are used to help pipe data from one CData cmdlet to another:

    $columns = ($data | Get-Member -MemberType NoteProperty | Select-Object -Property Name).Name | ? {$_ -NotIn @('Columns','Connection','Table')}

Ready to get started?

Download a free trial of the Cvent Cmdlets to get started:

 Download Now

Learn more:

Cvent Icon Cvent Data Cmdlets

An easy-to-use set of PowerShell Cmdlets offering real-time access to Cvent. The Cmdlets allow users to easily read, write, update, and delete live data - just like working with SQL server.