---
category: [Administration & Integrations, Platform and Product Extensions, Platform and Product Extensions/Integration, Administration & Integrations/Custom Integrations & Apps, Platform and Product Extensions/Workday Extend]
keyword: [Extend, Workday AI Gateway, AI Gateway]
nav: wcp_docs
parent_url: /wcp_docs/
title: Generate WQL REST API
layout: subsection
---

The Generate WQL REST API helps you to query Workday data sources by asking questions using natural language. Given a natural language query, the Generate WQL REST API maps the question to relevant data sources and returns the equivalent Workday Query Language (WQL) statement. You can use the WQL code to retrieve data and insights from the relevant data sources.

Sample use case:

-   As a developer, you may want to create an internal dashboard for your company to track job applications. You want to get the number of active applications, number of closed applications, and number of open job requisites. You can call the Generate WQL REST API to generate the necessary WQL queries that you can integrate with your Workday tenant.


By default, the generated WQL statement doesn’t include Workday IDs. To include Workday IDs of referenced instances in the generated WQL statement, specify the `user_oauth_token` in the request body.

## <a id="section_1"></a>URL Base Path

The Generate WQL REST API endpoint uses this base URL:

```
https://api.workday.com/ml/dataQuery/{version}
```

For regional URL base paths, see [Reference: Workday Extend API Gateways and Authorization Base URLs](/wcp_docs/dlh1653340161856.html).

## <a id="section_6"></a>Generating WQL Queries

To generate a WQL statement from a natural language question, call this endpoint:

```
POST {baseURL}/genWql
```

In the request body, specify:

-   `query` - (Required) A string containing a natural language query. The maximum length is 500 characters.
-   `user_oauth_token` - (Optional) The OAuth token that determines WQL access to tenant data. The token is used to resolve text comparisons with instance IDs in the generated WQL. If you don't specify the `user_oauth_token`, instance field comparisons will use text instead of Workday IDs. To get the token, you will need to register a WQL API client in the tenant and the `token` endpoint. For details, see [Get User OAuth Token for WQL Permissions](/wcp_docs/GUID-fc584935-9e80-442c-a398-07a157d2e8dd-enHYPHENus.html).


The endpoint searches the relevant data sources and fields, and returns the generated WQL statement if successful.

Response:

<table><thead><tr><th>Status Code</th><th>Description</th></tr></thead><tbody><tr><td>200</td><td><p>Returns a generated WQL statement in the format:</p> <p><code>{ "wql": string }</code></p></td></tr><tr><td>401</td><td>The client isn’t authenticated.</td></tr><tr><td>403</td><td><ul><li>Innovation Services not opted in. See <i>Tenant Availability and Setup</i> in <a href="/wcp_docs/GUID-6a9a5c40-42e1-4b9b-911d-ba5457fc61ce.html">Concept: Workday AI Gateway</a>.
</li><li>Insufficient permissions. Note that AI Gateway is available in:

<ul><li>Development tenants for all Extend customers.
</li><li>Non-Development tenants for Extend Professional customers <i>only</i>.
</li></ul></li></ul></td></tr><tr><td>422</td><td>Missing or invalid fields in the request body. Fix the required fields, as listed in the error messages.</td></tr><tr><td>501</td><td>Unable to process the query into a valid WQL statement. The response includes details to help with debugging. Example: Partially completed WQL statement, links to valid data sources, and others.</td></tr></tbody></table><br/>

## <a id="section_16"></a>Example

This sample request returns a WQL statement based on the input question.

```
POST https://api.workday.com/ml/dataQuery/v1/genWql
```

Request body:

```
{"query": "how many active workers were there one year ago"}
```

Sample response:

```
{  "wql": "SELECT COUNT() FROM allActiveAndTerminatedWorkers WHERE addedDate >= '2022-08-24' AND addedDate < '2022-09-24' AND workerActive = true"}
```

## <a id="section_4"></a>Limitations

-   Currently, the supported language is English only.
-   The query string must be less than or equal to 500 characters.


## <a id="section_17"></a>Getting Supported Data Sources

The Supported Data Sources endpoint returns the list of data sources that you can use with the Generate WQL REST API.

```
GET {baseURL}/supportedDataSources
```

You can include the name of a data source in your query text.

Response:

<table><thead><tr><th>Status Code</th><th>Description</th></tr></thead><tbody><tr><td>200</td><td><p>Returns a list of all the supported data sources:</p>```
[
{
"dataSourceName": string,
"dataSourceWid": string,
"dataSourceAlias": string
},
…
]
```

</td></tr><tr><td>401</td><td>The client isn’t authenticated.</td></tr><tr><td>403</td><td><ul><li>Innovation Services not opted in. See <i>Tenant Availability and Setup</i> in <a href="/wcp_docs/GUID-6a9a5c40-42e1-4b9b-911d-ba5457fc61ce.html">Concept: Workday AI Gateway</a>.
</li><li>Insufficient permissions. Note that AI Gateway is available in:

<ul><li>Development tenants for all Extend customers.
</li><li>Non-Development tenants for Extend Professional customers <i>only</i>.
</li></ul></li></ul></td></tr></tbody></table><br/>

Example:

```
GET https://api.workday.com/ml/dataQuery/v1/supportedDataSources
```

Sample response:

```
[
{
"dataSourceName": "Academic Appointees",
"dataSourceWid": "a30944f3991b10000ede48fb1b0d0019",
"dataSourceAlias": "academicAppointees"
},
{
"dataSourceName": "Academic Appointment Tracks",
"dataSourceWid": "ba7619f0ba0d4cd4bc82fae4824386fc",
"dataSourceAlias": "academicAppointmentTracks"
},
{
"dataSourceName": "Academic Appointments",
"dataSourceWid": "172b485372b2453cbe5ef9d2c82dae4d",
"dataSourceAlias": "academicAppointments"
},
{
"dataSourceName": "Academic Period Records",
"dataSourceWid": "5fa5cd1a72f91000243bdfb348890122",
"dataSourceAlias": "activeAcademicPeriodRecords"
},
{
"dataSourceName": "Academic Periods",
"dataSourceWid": "ff1389e713361000187679b7674c00f2",
"dataSourceAlias": "academicPeriods"
},
. . .
]
```

