Connect to Paylocity Data from Blazor Apps



Build ASP.NET Core Blazor C# apps that integrate with real-time Paylocity data using standard SQL.

Blazor is a framework for developing modern, client-side web UIs using .NET technology. Instead of coding in JavaScript, developers can use the familiar C# language and .NET libraries to build app UIs.

The CData ADO.NET Provider for Paylocity can be used with standard ADO.NET interfaces, such as LINQ and Entity Framework, to interact with live Paylocity data. Since Blazor supports .NET Core, developers can use CData ADO.NET Providers in Blazor apps. In this article, we will guide you to build a simple Blazor app that talks to Paylocity using standard SQL queries.

Install the CData ADO.NET Provider for Paylocity

CData ADO.NET Providers allow users to access Paylocity just like they would access SQL Server, using simple SQL queries.

Install the Paylocity ADO.NET Data Provider from the CData website or from NuGet. Search NuGet for "Paylocity ADO.NET Data Provider."

Create a Paylocity-Connected Blazor App

Start by creating a Blazor project that references the CData ADO.NET Provider for Paylocity

  1. Create a Blazor project on Visual Studio.
  2. From the Solution Explorer, right click Dependencies, then click Add Project Reference.
  3. In the Reference Manager, click the Browse button, and choose the .dll file of the installed ADO.NET Provider (e.g. System.Data.CData.Paylocity.dll, typically located at C:\Program Files\CData\CData ADO.NET Provider for Paylocity\lib etstandard2.0).

SELECT Paylocity Data from the Blazor App

  1. Open the Index.razor file from the Project page.
  2. In a PaylocityConnection object, set the connection string:

    Set the following to establish a connection to Paylocity:

    • RSAPublicKey: Set this to the RSA Key associated with your Paylocity, if the RSA Encryption is enabled in the Paylocity account.

      This property is required for executing Insert and Update statements, and it is not required if the feature is disabled.

    • UseSandbox: Set to true if you are using sandbox account.
    • CustomFieldsCategory: Set this to the Customfields category. This is required when IncludeCustomFields is set to true. The default value for this property is PayrollAndHR.
    • Key: The AES symmetric key(base 64 encoded) encrypted with the Paylocity Public Key. It is the key used to encrypt the content.

      Paylocity will decrypt the AES key using RSA decryption.
      It is an optional property if the IV value not provided, The driver will generate a key internally.

    • IV: The AES IV (base 64 encoded) used when encrypting the content. It is an optional property if the Key value not provided, The driver will generate an IV internally.

    Connect Using OAuth Authentication

    You must use OAuth to authenticate with Paylocity. OAuth requires the authenticating user to interact with Paylocity using the browser. For more information, refer to the OAuth section in the Help documentation.

    The Pay Entry API

    The Pay Entry API is completely separate from the rest of the Paylocity API. It uses a separate Client ID and Secret, and must be explicitly requested from Paylocity for access to be granted for an account. The Pay Entry API allows you to automatically submit payroll information for individual employees, and little else. Due to the extremely limited nature of what is offered by the Pay Entry API, we have elected not to give it a separate schema, but it may be enabled via the UsePayEntryAPI connection property.

    Please be aware that when setting UsePayEntryAPI to true, you may only use the CreatePayEntryImportBatch & MergePayEntryImportBatchgtable stored procedures, the InputTimeEntry table, and the OAuth stored procedures. Attempts to use other features of the product will result in an error. You must also store your OAuthAccessToken separately, which often means setting a different OAuthSettingsLocation when using this connection property.

    For example: OAuthClientID=YourClientId;OAuthClientSecret=YourClientSecret;RSAPublicKey=YourRSAPubKey;Key=YourKey;IV=YourIV;

  3. The code below creates a simple Blazor app for displaying Paylocity data, using standard SQL to query Paylocity just like SQL Server.

          @page "/"
          @using System.Data;
          @using System.Data.CData.Paylocity;
          
          <h1>Hello, world!</h1>
          
          Welcome to your Data app.
          
          <div class="row">
              <div class="col-12">
          
                  @using (PaylocityConnection connection = new PaylocityConnection(
                    "OAuthClientID=YourClientId;OAuthClientSecret=YourClientSecret;RSAPublicKey=YourRSAPubKey;Key=YourKey;IV=YourIV;"))
                  {
                      var sql = "SELECT FirstName, LastName FROM Employee WHERE EmployeeId = '1234'";
                      var results = new DataTable();
          
                      PaylocityDataAdapter dataAdapter = new PaylocityDataAdapter(sql, connection);
                      dataAdapter.Fill(results);
          
                      <table class="table table-bordered">
                          <thead class="thead-light">
                              <tr>
                                  @foreach (DataColumn item in results.Rows[0].Table.Columns)
                                  {
                                      <th scope="col">@item.ColumnName</th>
                                  }
                              </tr>
                          </thead>
                          <tbody>
                              @foreach (DataRow row in results.Rows)
                              {
                                  <tr>
                                      @foreach (var column in row.ItemArray)
                                      {
                                          <td>@column.ToString()</td>
                                      }
                                  </tr>
                              }
                          </tbody>
                      </table>
                  }
              </div>
          </div>
        
  4. Rebuild and run the project. The ADO.NET Provider renders Paylocity data as an HTML table in the Blazor app.

    At this point, you have a Paylocity-connected Blazor app, capable of working with live Paylocity data just like you would work with a SQL Server instance. Download a free, 30-day trial and start working with live Paylocity data in your Blazor apps today.

Ready to get started?

Download a free trial of the Paylocity Data Provider to get started:

 Download Now

Learn more:

Paylocity Icon Paylocity ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Paylocity.