Structuring & Sending a Query
This guide provides the basic structure of a VQL query and how to submit it to retrieve document and object fields.
Structuring a Query
Section link for Structuring a QueryVQL’s syntax is similar to SQL and provides a programmatic way of searching your Vault’s data. A basic VQL query consists of a SELECT statement with a FROM clause:
SELECT {fields}
FROM {query target}The SELECT clause provides the fields to retrieve from the specified query target, such as id. The FROM clause provides the query target, such as documents.
For example, to retrieve the latest version of all documents from a Vault, use this basic query:
SELECT id
FROM documentsSending a Query
Section link for Sending a QueryTo send a VQL query, send a POST request to the /api/{version}/query endpoint as shown in the Vault API Reference. Using POST allows you to send a VQL statement of up to 50,000 characters.
The following example sends a query that retrieves the ID and name of all documents in the specified Vault:
curl -X POST -H "Authorization: {session_id}" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'q=select id, name__v from documents' \
"https://myvault.veevavault.com/api/v20.3/query"The VQL API response includes a data payload with the requested fields:
Response
Section link for Response{
"responseStatus": "SUCCESS",
"responseDetails": {
"pagesize": 1000,
"pageoffset": 0,
"size": 96,
"total": 96
},
"data": [
{
"id": 119,
"name__v": "CholeCap Batch Manufacturing RecordTest File 1"
},
{
"id": 1,
"name__v": "CholeCap Visual AidTest File 2"
}
]
}