> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peliqan.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Workday - Getting started in Peliqan

> Connect Workday to Peliqan using OAuth authorization. Create an API client in Workday, sync reports via WQL queries, and load the data into Peliqan's data warehouse with custom pipeline scripts.

*Workday is a SaaS for financial management, human capital management, and a student information system.*

This article provides an overview to get started with the **Workday** connector in **Peliqan**. Please [contact support](https://peliqan.io/contact) if you have any additional questions or remarks.

## Connect Workday

Create an app (API client) in Workday first.

Settings:

* Client Grant Type: select "Authorization Code Grant"
* Access Token Type: select "Bearer"
* Redirection URI: enter [https://oauth.peliqan.io/](https://oauth.peliqan.io/)
* Check: "Non-Expiring Refresh Tokens"
* Add all scopes
* Check "Include Workday Owned Scope"
* Copy the **Client ID** and **Client Secret** (only shown once) and enter them in the connection in Peliqan

Example:

![Workday app settings in Workday UI](https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/e1ad030b-03f5-4c22-b491-e91f9fb76bbf/Workday_app/w=1920,quality=90,fit=scale-down)

## Sync data from Workday reports to the data warehouse

Getting data from Workday reports can be done using a custom pipeline script in Peliqan. The report must be converted to WQL in Workday first.

In Workday, go to "Convert Report to WQL" and select the report to convert.

Workday will display the WQL query to use, to fetch the data from the report.

![Workday Convert Report to WQL screen](https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/7d5220a8-6c08-49a0-bdee-a36797ec3bb3/Workday_convert_report_to_wQL_errors_on_invalid_columns/w=1920,quality=90,fit=scale-down)

Next, use a custom pipeline script in Peliqan to fetch the data.

<Accordion title="Example custom pipeline to fetch Workday data using a WQL query (e.g. report data), click to expand">
  ```python theme={null}
  dbconn = pq.dbconnect(pq.DW_NAME)    
  workday_api = pq.connect('Workday')

  def get_wql_data_allWorkers():
      table_name = "allworkers"
      query = "SELECT workerID, worker, employee, position FROM allWorkers"

      workday_api.get('wql', limit=1, offset="", query=query) # first API request needs to be without offset
      
      offset = 0
      limit = 1000
      
      while True:
          st.text(f"Fetching wQL query data with limit {limit} and offset {offset}.")
          result = workday_api.get('wql', limit=limit, offset=offset, query=query)

          if not "data" in result:
              break
          else:
              data = result["data"]
              
              for record in data:
                  record["id"] = record.get("worker", {}).get("id", "") + "_" + record.get("employee", {}).get("id", "")    # create unique id for each row
              
              dbconn.write('wql', table_name, records=data, pk='id')
          
              offset += limit
              if len(data)==0:
                  break

  get_wql_data_allWorkers()
  ```
</Accordion>

<Accordion title="Example custom pipeline to fetch Workday data using a WQL query (e.g. report data), click to expand">
  ```python theme={null}
  dbconn = pq.dbconnect(pq.DW_NAME)    
  workday_api = pq.connect('Workday')

  def get_wql_data_allWorkers():
      table_name = "allworkers"
      query = "SELECT workerID, worker, employee, position FROM allWorkers"

      workday_api.get('wql', limit=1, offset="", query=query) # first API request needs to be without offset
      
      offset = 0
      limit = 1000
      
      while True:
          st.text(f"Fetching wQL query data with limit {limit} and offset {offset}.")
          result = workday_api.get('wql', limit=limit, offset=offset, query=query)

          if not "data" in result:
              break
          else:
              data = result["data"]
              
              for record in data:
                  record["id"] = record.get("worker", {}).get("id", "") + "_" + record.get("employee", {}).get("id", "")    # create unique id for each row
              
              dbconn.write('wql', table_name, records=data, pk='id')
          
              offset += limit
              if len(data)==0:
                  break

  get_wql_data_allWorkers()
  ```
</Accordion>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.