Skip to main content
POST
/
source-creator
/
generate-queries
Step 3 — Generate BigQuery SQL from confirmed mappings
curl --request POST \
  --url https://api.royalti.io/source-creator/generate-queries \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "sessionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "tableNameFormat": "<string>"
}
'
import requests

url = "https://api.royalti.io/source-creator/generate-queries"

payload = {
"sessionId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"tableNameFormat": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({sessionId: '3c90c3cc-0d44-4b50-8888-8dd25736052a', tableNameFormat: '<string>'})
};

fetch('https://api.royalti.io/source-creator/generate-queries', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.royalti.io/source-creator/generate-queries",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sessionId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'tableNameFormat' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.royalti.io/source-creator/generate-queries"

payload := strings.NewReader("{\n \"sessionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"tableNameFormat\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.royalti.io/source-creator/generate-queries")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sessionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"tableNameFormat\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.royalti.io/source-creator/generate-queries")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sessionId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"tableNameFormat\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "status": "success",
  "message": "Queries generated successfully",
  "data": {
    "salesDataQuery": "<string>",
    "royaltySumQuery": "<string>",
    "countSumQuery": "<string>",
    "columnFormatDSL": "<string>",
    "explanation": "<string>",
    "warnings": [
      "<string>"
    ]
  }
}
{
"status": "error",
"message": "<string>"
}
{
"status": "error",
"message": "This feature requires a plan upgrade",
"data": {
"feature": "royaltyAccess",
"currentPlan": "FREE",
"availablePlans": [
{}
]
}
}
{
"status": "error",
"message": "<string>"
}
This endpoint requires authentication. Include your Bearer token in the Authorization header.

Description

POST /source-creator/generate-queries Description: Generates the sales-data view query, royalty-sum query, and row-count query from the session’s confirmed mappings. Auto-derives tableNameFormat from the source name and the resolved accounting/sale period-source mode (column/filename/none) unless explicitly overridden. For “copy & modify” sessions (parentSourceId set), also infers transform patterns (exchange-rate join, COALESCE quantity fallback, nullIf, DSP override) from the parent source’s SQL and computes a versioned tableNameFormat. AI-calling — rate limited via aiRateLimitMiddleware. (Query building itself runs synchronously through QueryBuilderService, not an AI call, but the route carries the same limiter as ai-map-columns.) Authorization:
  • Required role: admin or higher
Method: POST

Code Examples

const response = await fetch('https://api.royalti.io/source-creator/generate-queries', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "ref": "#/components/schemas/GenerateQueriesRequest"
  })
});

const data = await response.json();
console.log(data);
import requests

response = requests.post(
  'https://api.royalti.io/source-creator/generate-queries',
  headers={
    'Authorization': f'Bearer {token}'
  },
  json={"ref":"#/components/schemas/GenerateQueriesRequest"}
)

data = response.json()
print(data)
curl -X POST https://api.royalti.io/source-creator/generate-queries \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ref":"#/components/schemas/GenerateQueriesRequest"}'

Authorizations

Authorization
string
header
required

JWT Authorization header using the Bearer scheme. Format: "Bearer {token}"

Body

application/json
sessionId
string<uuid>
required
tableNameFormat
string | null

Explicit BigQuery table-name template override. Auto-derived from source name + period-source mode when omitted.

accountingPeriodSource
enum<string>

Overrides the auto-inferred accounting-period source mode.

Available options:
column,
filename,
none
salePeriodSource
enum<string>

Overrides the auto-inferred sale-period source mode.

Available options:
column,
filename,
none

Response

Queries generated successfully

status
string
Example:

"success"

message
string
Example:

"Queries generated successfully"

data
object