With the GraphQL load method, Doctavian doesn't read a stored file: it calls an external API at generation time and uses the result as the template's data. Use it when your data lives in a live system and you'd rather not export and upload a JSON file before every run. For file-based data, see Set up Data Sources.
| Field | Meaning for GraphQL |
|---|---|
loadMethod | "GraphQL" |
urn | The URL of the external API to call. It does not have to be a true GraphQL endpoint: a plain REST endpoint works too, and is called with a PUT request instead of a GraphQL query |
query | The GraphQL request body, as a JSON-serialized string — for example "{\"query\":\"{...}\"}". Optional |
variables | Optional. A graphql-type variable supplies the value for a $ variable the query references. global and fieldExpression variables can be added too, as for any data source |
Doctavian combines urn, query and variables to build the call, and turns the result into the data the template consumes — the same data format as an uploaded file: an object whose data property holds named lists of records. Unlike a Storage file, nothing is consumed: the endpoint is called again on each generation.
data object whose every member is a list of records. That includes the top-level objects of your query — even when the query returns a single record, as Opportunity(Id: $recordId) does, it comes back as a list of one.For the query in Writing the query, below, the endpoint returns something like this (shortened):
{
"data": {
"Opportunity": [
{
"Id": "0065g00000XyZaBAAV",
"Name": "Acme Logistics — Fleet Renewal",
"CloseDate": "Dec 15, 2026",
"Amount": "48,000.00",
"OpportunityLineItems": [
{ "Id": "00k5g00000Ab1CDAAZ", "Name": "Telematics unit", "Quantity": "40", "UnitPrice": "1,200.00", "TotalPrice": "48,000.00" }
]
}
],
"Account": [ { "Id": "0015g00000AbCdEAAV", "Name": "Acme Logistics Group", "BillingCity": "Dublin" } ],
"Organization": [ { "Name": "World Industries", "City": "Dublin" } ],
"SalesAgent": [ { "Id": "0055g00000QrStUAAV", "Name": "Alex Morgan", "Email": "alex.morgan@worldindustries.com" } ]
}
}Values should be strings already formatted for the locale you generate in — see Data Sources for the format in full.
The query names the objects your template needs and, inside each, the fields to return. This one gathers everything for a sales quote: the opportunity with its line items, the customer's account, your own organization, and the sales agent who owns the deal.
{
Opportunity(Id: $recordId) {
Id
Name
CreatedDate
CloseDate
Amount
OpportunityLineItems {
Id
Name
Quantity
UnitPrice
TotalPrice
}
}
Account(Id: $accountId) {
Id
Name
BillingStreet
BillingCity
BillingPostalCode
BillingCountry
}
Organization {
Name
Street
City
PostalCode
Country
}
SalesAgent:User(Id: $ownerId) {
Id
Name
Email
Phone
}
}$recordId, $accountId and $ownerId are filled in from the graphql variables you send with the data source, so the same query serves every record. Organization takes no argument.OpportunityLineItems comes back as a list inside the opportunity — the collections a Repeater or Table in your template iterates over.SalesAgent:User queries User but returns it under the name SalesAgent, so the template reads SalesAgent.Name. Use an alias when the same object is needed twice, or when a clearer name helps the template.To send the query, serialize it into the query property as a JSON string, as in the examples below.
On POST /documents/document/generate (or /generate/async), set the data object to the GraphQL method. Nothing needs to be created first:
POST https://api.doctavian.com/v1/documents/document/generate
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"template": {
"urn": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5",
"loadMethod": "Storage",
"fileFormat": "docx"
},
"data": {
"loadMethod": "GraphQL",
"urn": "https://api.your-system.example.com/graphql",
"query": "{\"query\":\"{ Opportunity(Id: $recordId) { Id Name CreatedDate CloseDate Amount OpportunityLineItems { Id Name Quantity UnitPrice TotalPrice } } Account(Id: $accountId) { Id Name BillingStreet BillingCity BillingPostalCode BillingCountry } Organization { Name Street City PostalCode Country } SalesAgent:User(Id: $ownerId) { Id Name Email Phone } }\"}",
"variables": [
{ "name": "recordId", "value": "0065g00000XyZaBAAV", "type": "graphql" },
{ "name": "accountId", "value": "0015g00000AbCdEAAV", "type": "graphql" },
{ "name": "ownerId", "value": "0055g00000QrStUAAV", "type": "graphql" },
{ "name": "Opportunity.GeneratedOn", "value": "{!$now()}", "type": "fieldExpression" }
]
},
"document": {
"name": "Quote Q-2026-0042",
"fileFormat": "pdf",
"deliveryMethod": "Storage",
"path": "root",
"locale": "en-IE",
"timeZone": "Europe/Dublin"
}
}The response is the same as any generate request — see Generate Document, Step 3.
queryis a string containing JSON, not a nested object. Serialize your GraphQL request body and escape it, as in the example.
To generate through Document Solutions and Document Requests, save the same settings as a Data Source:
POST https://api.doctavian.com/v1/documents/datasource/create
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"dataSource": {
"name": "Opportunity quote data",
"description": "Opportunity, account, organization and sales agent fetched at generation time.",
"loadMethod": "GraphQL",
"urn": "https://api.your-system.example.com/graphql",
"query": "{\"query\":\"{ Opportunity(Id: $recordId) { Id Name CreatedDate CloseDate Amount OpportunityLineItems { Id Name Quantity UnitPrice TotalPrice } } Account(Id: $accountId) { Id Name BillingStreet BillingCity BillingPostalCode BillingCountry } Organization { Name Street City PostalCode Country } SalesAgent:User(Id: $ownerId) { Id Name Email Phone } }\"}",
"variables": [
{ "name": "recordId", "value": "0065g00000XyZaBAAV", "type": "graphql" },
{ "name": "accountId", "value": "0015g00000AbCdEAAV", "type": "graphql" },
{ "name": "ownerId", "value": "0055g00000QrStUAAV", "type": "graphql" }
]
}
}The new id is at result.data.dataSource.id. Attach the Data Source to a solution and reference it as dataSourceId on a Document Request, as for any data source.
query is stored exactly as supplied and its syntax is not validated when you save it. Problems surface when the data is loaded.PUT /documents/datasource/{dataSourceId}/update) is a full replacement: resend query and variables with every update, or they are cleared.Before generating, call POST /documents/datasource/{dataSourceId}/data/load. It calls your endpoint exactly as generation would and returns the resulting data — the quickest way to confirm the endpoint, query and variables work and to see the object and field names to use in your template.
Pass variable values for this load only in variables — note the different shape: just name and value, matched by name to the variables the Data Source declares. They are not saved on the Data Source.
POST https://api.doctavian.com/v1/documents/datasource/5b2e8c71-0d4f-4a93-b6e1-9c3a7f2d1e58/data/load
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"variables": [
{ "name": "recordId", "value": "0065g00000LmNoPAAV" }
],
"maxItems": 5,
"externalContext": { "check": "graphql-smoke-test" }
}{
"result": {
"data": {
"dataSourceData": {
"data": {
"Opportunity": [
{
"Id": "0065g00000LmNoPAAV",
"Name": "Acme Logistics — Fleet Renewal",
"CloseDate": "Dec 15, 2026",
"Amount": "48,000.00",
"OpportunityLineItems": [
{ "Name": "Telematics unit", "Quantity": "40", "UnitPrice": "1,200.00", "TotalPrice": "48,000.00" }
]
}
],
"Account": [ { "Name": "Acme Logistics Group", "BillingCity": "Dublin" } ],
"SalesAgent": [ { "Name": "Alex Morgan", "Email": "alex.morgan@worldindustries.com" } ]
}
},
"truncated": true
}
},
"externalContext": { "check": "graphql-smoke-test" },
...
}maxItems keeps only the first n entries of every array; truncated is true when that cut at least one array short.
When the load fails, the error code tells you whether the URL, the call to your endpoint, or the shape of the result was the problem — for example, a result that is not JSON or has no data property. The codes are listed in the API Reference.
urn, query and variables define a call to a GraphQL or REST endpoint