Generar código de plantilla
curl --request POST \
--url http://localhost:4005/v1/templates/generate-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"blocks": [
{
"type": "variable",
"variable": "account.id"
}
],
"format": "html"
}
'import requests
url = "http://localhost:4005/v1/templates/generate-code"
payload = {
"blocks": [
{
"type": "variable",
"variable": "account.id"
}
],
"format": "html"
}
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({blocks: [{type: 'variable', variable: 'account.id'}], format: 'html'})
};
fetch('http://localhost:4005/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_PORT => "4005",
CURLOPT_URL => "http://localhost:4005/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([
'blocks' => [
[
'type' => 'variable',
'variable' => 'account.id'
]
],
'format' => 'html'
]),
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 := "http://localhost:4005/v1/templates/generate-code"
payload := strings.NewReader("{\n \"blocks\": [\n {\n \"type\": \"variable\",\n \"variable\": \"account.id\"\n }\n ],\n \"format\": \"html\"\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("http://localhost:4005/v1/templates/generate-code")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"blocks\": [\n {\n \"type\": \"variable\",\n \"variable\": \"account.id\"\n }\n ],\n \"format\": \"html\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:4005/v1/templates/generate-code")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"blocks\": [\n {\n \"type\": \"variable\",\n \"variable\": \"account.id\"\n }\n ],\n \"format\": \"html\"\n}"
response = http.request(request)
puts response.read_body{
"code": "{{ account.id }}",
"mappedFields": {
"primary": {
"account": [
"id"
]
}
}
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}Generar código de plantilla
Utiliza este endpoint para convertir una secuencia estructurada de bloques de plantilla en código de plantilla Pongo2. La respuesta devuelve el código generado junto con los campos de datos que referencia, de modo que puedas previsualizar una plantilla antes de guardarla.
POST
/
v1
/
templates
/
generate-code
Generar código de plantilla
curl --request POST \
--url http://localhost:4005/v1/templates/generate-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"blocks": [
{
"type": "variable",
"variable": "account.id"
}
],
"format": "html"
}
'import requests
url = "http://localhost:4005/v1/templates/generate-code"
payload = {
"blocks": [
{
"type": "variable",
"variable": "account.id"
}
],
"format": "html"
}
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({blocks: [{type: 'variable', variable: 'account.id'}], format: 'html'})
};
fetch('http://localhost:4005/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_PORT => "4005",
CURLOPT_URL => "http://localhost:4005/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([
'blocks' => [
[
'type' => 'variable',
'variable' => 'account.id'
]
],
'format' => 'html'
]),
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 := "http://localhost:4005/v1/templates/generate-code"
payload := strings.NewReader("{\n \"blocks\": [\n {\n \"type\": \"variable\",\n \"variable\": \"account.id\"\n }\n ],\n \"format\": \"html\"\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("http://localhost:4005/v1/templates/generate-code")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"blocks\": [\n {\n \"type\": \"variable\",\n \"variable\": \"account.id\"\n }\n ],\n \"format\": \"html\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:4005/v1/templates/generate-code")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"blocks\": [\n {\n \"type\": \"variable\",\n \"variable\": \"account.id\"\n }\n ],\n \"format\": \"html\"\n}"
response = http.request(request)
puts response.read_body{
"code": "{{ account.id }}",
"mappedFields": {
"primary": {
"account": [
"id"
]
}
}
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}{
"code": "ERR-0001",
"detail": "Property foo is required but is missing.",
"errors": [
{
"location": "body.templateId",
"message": "expected string to match 'uuid' format",
"value": "not-a-uuid"
}
],
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "https://example.com/errors/example"
}Autorizaciones
Autenticación mediante token Bearer. Formato: 'Bearer {access_token}'. Solo es obligatoria cuando el plugin de autenticación está habilitado.
Cuerpo
application/json
Bloques de la plantilla y formato de salida objetivo.
¿Esta página le ayudó?

