Getting Started with the Veeva Vault REST API and VQL: Auth, Syntax & Pagination
If you are integrating an external web app, data pipeline, or ERP with Veeva Vault, you will spend most of your time working with two things: the Vault REST API and VQL (Vault Query Language).
While VQL looks like standard SQL at first glance, it has strict rules around authentication headers, field suffixes (__v, __c, __r), pagination (next_page, MAXROWS, PAGESIZE), and POST vs. GET query limits. This guide walks through the complete workflow from authentication to production-safe pagination.
Interactive Companion Tool: Format, lint, and wrap your queries into cURL or
fetchrequests instantly with our Veeva VQL Formatter & Linter.
1. Authentication & Session IDs (/api/{version}/auth)
Every Vault REST API request requires a valid sessionId passed in the Authorization header (note: Veeva uses the raw sessionId value, not Bearer <token>).
Step 1: Request a Session ID
Send a POST request with application/x-www-form-urlencoded credentials to /api/{version}/auth:
curl -X POST "https://{vault-dns}.veevavault.com/api/v25.1/auth" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
--data-urlencode "username=api.user@company.com" \
--data-urlencode "password=your-password"
A successful response returns responseStatus: "SUCCESS" along with your sessionId:
{
"responseStatus": "SUCCESS",
"sessionId": "5F8A9C2D1E...",
"userId": 102458,
"vaultIds": [
{
"id": 12345,
"name": "Company Clinical Vault",
"url": "https://company-clinical.veevavault.com/api"
}
]
}
Step 2: Pass sessionId on Subsequent Requests
Include Authorization: {sessionId} in every VQL query or object request. Always reuse your active session until it expires rather than calling /auth on every request.
2. Executing VQL Queries (POST /api/{version}/query)
Although the Vault Query endpoint supports GET /api/v25.1/query?q=..., always prefer POST with Content-Type: application/x-www-form-urlencoded in production:
GETURLs hit length limits (~6,000 characters) on longIN (...)lists.POSTsupports much larger queries (~50,000 characters) and avoids URL-encoding issues in server logs.
const vql = `
SELECT
id,
name__v,
status__v
FROM
documents
WHERE
status__v = 'steady_state__v'
ORDER BY
id ASC
MAXROWS 500
PAGESIZE 100
`;
const response = await fetch("https://{vault-dns}.veevavault.com/api/v25.1/query", {
method: "POST",
headers: {
Authorization: sessionId,
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
body: new URLSearchParams({ q: vql.trim() }),
});
const result = await response.json();
You can generate this exact cURL or fetch snippet from any query using the Veeva VQL Formatter & Linter.
3. Understanding __v, __c, and __r Naming in VQL
Every object and field in Veeva Vault carries a suffix that tells you who owns it and how to query it:
| Suffix | Meaning | VQL Example |
|---|---|---|
__v |
Standard Veeva-managed object or field | SELECT id, name__v FROM product__v |
__c |
Custom admin-created object or field | SELECT study_phase__c FROM clinical_study__c |
__vr / __cr / __r |
Relationship name for dot-notation joins | SELECT study__vr.name__v FROM study_country__v |
__sys |
Vault system object or field | SELECT username__sys FROM user__sys |
Common Gotcha: Joining Parent Fields
If study__v is a reference field on study_country__v, selecting study__v returns only the record ID. To pull the parent record's name or status in the same query, use the relationship suffix (__vr for standard, __cr for custom):
SELECT
id,
name__v,
study__vr.name__v,
study__vr.status__v
FROM
study_country__v
WHERE
study__vr.status__v = 'active__v'
Need to convert human labels into valid __c or __cr API names? Try our Veeva API Name Generator & Field Naming Checker.
4. Essential VQL Rules & Functions
Keep these Vault-specific rules in mind to avoid parser errors:
- No
SELECT *: VQL requires explicit field names (SELECT id, name__v). FIND ('...' SCOPE ...): Full-text search across documents or objects, optionally scoped to specific fields:SELECT id, name__v FROM documents FIND ('protocol' SCOPE name__v, title__v)LONGTEXT()andRICHTEXT(): By default, LongText and RichText fields truncate at 250 characters. Wrap them with anASalias to retrieve the full value:SELECT id, LONGTEXT(description__c) AS full_description FROM study__c
5. Pagination (PAGESIZE, MAXROWS, SKIP, and next_page)
Veeva Vault paginates query results automatically (typically 200 records per page for documents and 1,000 for Vault objects).
Rule 1: MAXROWS Must Precede PAGESIZE
When combining both clauses, MAXROWS must come first:
SELECT
id,
name__v
FROM
documents
WHERE
status__v = 'steady_state__v'
ORDER BY
id ASC
MAXROWS 500
PAGESIZE 100
Rule 2: Follow responseDetails.next_page
For large datasets, avoid manually incrementing SKIP without an ORDER BY clause. Instead, check responseDetails.next_page in the JSON response and request that URL until next_page is absent:
let nextUrl = null;
const allRecords = [];
// Initial POST query...
// Then loop while result.responseDetails?.next_page exists:
while (nextUrl) {
const pageRes = await fetch(`https://{vault-dns}.veevavault.com${nextUrl}`, {
headers: {
Authorization: sessionId,
Accept: "application/json",
},
});
const pageData = await pageRes.json();
allRecords.push(...(pageData.data ?? []));
nextUrl = pageData.responseDetails?.next_page ?? null;
}
Related Veeva Tools & Guides
- Tool: Veeva VQL Formatter & Linter — Pretty-print VQL, catch
SELECT *orMAXROWS/PAGESIZEerrors, and export cURL/fetch snippets. - Tool: Veeva Vault API Pagination & Request Calculator — Estimate
next_pageAPI calls and runtime before running large extracts. - Tool: Veeva Vault Criteria VQL Generator — Build Reference Constraints and Sharing Rules for Vault Admin.
- Tool: Veeva API Name Generator — Convert field labels to
__c/__crAPI names. - Guide: What Is Veeva Systems? Complete Guide to Veeva Vault Products — Architecture overview of Commercial Cloud and Development Cloud.
- Hub: All 15 Veeva Developer & Admin Tools
