Skip to main content
POST
/
v1
/
templates
/
generate-code
Generate Template Code
curl --request POST \
  --url https://reporter.sandbox.lerian.net/v1/templates/generate-code \
  --header 'Content-Type: application/json' \
  --header 'X-Organization-id: <x-organization-id>' \
  --data '
{
  "format": "TXT",
  "blocks": [
    {
      "type": "loop",
      "collection": "accounts",
      "iterator": "account",
      "children": [
        {
          "type": "field",
          "field": "account.name"
        }
      ]
    }
  ]
}
'
import requests

url = "https://reporter.sandbox.lerian.net/v1/templates/generate-code"

payload = {
"format": "TXT",
"blocks": [
{
"type": "loop",
"collection": "accounts",
"iterator": "account",
"children": [
{
"type": "field",
"field": "account.name"
}
]
}
]
}
headers = {
"X-Organization-id": "<x-organization-id>",
"Content-Type": "application/json"
}

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

print(response.text)
const options = {
method: 'POST',
headers: {'X-Organization-id': '<x-organization-id>', 'Content-Type': 'application/json'},
body: JSON.stringify({
format: 'TXT',
blocks: [
{
type: 'loop',
collection: 'accounts',
iterator: 'account',
children: [{type: 'field', field: 'account.name'}]
}
]
})
};

fetch('https://reporter.sandbox.lerian.net/v1/templates/generate-code', 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://reporter.sandbox.lerian.net/v1/templates/generate-code",
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([
'format' => 'TXT',
'blocks' => [
[
'type' => 'loop',
'collection' => 'accounts',
'iterator' => 'account',
'children' => [
[
'type' => 'field',
'field' => 'account.name'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Organization-id: <x-organization-id>"
],
]);

$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://reporter.sandbox.lerian.net/v1/templates/generate-code"

payload := strings.NewReader("{\n \"format\": \"TXT\",\n \"blocks\": [\n {\n \"type\": \"loop\",\n \"collection\": \"accounts\",\n \"iterator\": \"account\",\n \"children\": [\n {\n \"type\": \"field\",\n \"field\": \"account.name\"\n }\n ]\n }\n ]\n}")

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

req.Header.Add("X-Organization-id", "<x-organization-id>")
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://reporter.sandbox.lerian.net/v1/templates/generate-code")
.header("X-Organization-id", "<x-organization-id>")
.header("Content-Type", "application/json")
.body("{\n \"format\": \"TXT\",\n \"blocks\": [\n {\n \"type\": \"loop\",\n \"collection\": \"accounts\",\n \"iterator\": \"account\",\n \"children\": [\n {\n \"type\": \"field\",\n \"field\": \"account.name\"\n }\n ]\n }\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://reporter.sandbox.lerian.net/v1/templates/generate-code")

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

request = Net::HTTP::Post.new(url)
request["X-Organization-id"] = '<x-organization-id>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"format\": \"TXT\",\n \"blocks\": [\n {\n \"type\": \"loop\",\n \"collection\": \"accounts\",\n \"iterator\": \"account\",\n \"children\": [\n {\n \"type\": \"field\",\n \"field\": \"account.name\"\n }\n ]\n }\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "code": "{% for account in accounts %}{{ account.name }}{% endfor %}",
  "mappedFields": {
    "accounts": [
      "name"
    ]
  }
}

Headers

Authorization
string

The authorization token in the 'Bearer ' format.

Important: This header is required if your environment has Access Manager enabled. For more information, refer to the Access Manager documentation.

X-Organization-id
string
required

The unique identifier of the Organization associated with the request.

Body

application/json
blocks
object[]

The ordered sequence of template blocks to convert.

format
string

The output format the template targets (for example, HTML, CSV, or TXT).

Response

The generated template code and the fields it references.

code
string

The generated Pongo2 template code.

mappedFields
object

The data-source fields referenced by the generated code.